﻿/***
 *
 *  Base64 encode / decode
 *  http://www.webtoolkit.info/
 *
 **/
// ALK Note: we might want to rewrite this.
// webtoolkit.info license doesn't permit removal of comments which js minifiers do.
// also utf8 handling functions are not really utf8, but CESU-8.
// I.e. it doesn't handle utf16 surrogate pairs at all
/**
使用示例
 f.decode.value = Base64.decode(f.output.value)
 f.output.value =Base64.encode (f.source.value)
*/

var Base64 = {

    // private property
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode: function(input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
                this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
                this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode: function(input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
        //		string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            } else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            } else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            } else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            } else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

};


var base64encodechars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`/";
var base64decodechars = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

function base64encode(str) {
    var out, i, len;
    var c1, c2, c3;
    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        c1 = str.charCodeAt(i++) & 0xff;
        if (i == len) {
            out += base64encodechars.charAt(c1 >> 2);
            out += base64encodechars.charAt((c1 & 0x3) << 4);
            out += "==";
            break;
        }
        c2 = str.charCodeAt(i++);
        if (i == len) {
            out += base64encodechars.charAt(c1 >> 2);
            out += base64encodechars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));
            out += base64encodechars.charAt((c2 & 0xf) << 2);
            out += "=";
            break;
        }
        c3 = str.charCodeAt(i++);
        out += base64encodechars.charAt(c1 >> 2);
        out += base64encodechars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));
        out += base64encodechars.charAt(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6));
        out += base64encodechars.charAt(c3 & 0x3f);
    }
    return out;
}

function base64decode(str) {
    var c1, c2, c3, c4;
    var i, len, out;

    len = str.length;

    i = 0;
    out = "";
    while (i < len) {

        do {
            c1 = base64decodechars[str.charCodeAt(i++) & 0xff];
        } while (i < len && c1 == -1);
        if (c1 == -1)
            break;


        do {
            c2 = base64decodechars[str.charCodeAt(i++) & 0xff];
        } while (i < len && c2 == -1);
        if (c2 == -1)
            break;

        out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));


        do {
            c3 = str.charCodeAt(i++) & 0xff;
            if (c3 == 61)
                return out;
            c3 = base64decodechars[c3];
        } while (i < len && c3 == -1);
        if (c3 == -1)
            break;

        out += String.fromCharCode(((c2 & 0xf) << 4) | ((c3 & 0x3c) >> 2));


        do {
            c4 = str.charCodeAt(i++) & 0xff;
            if (c4 == 61)
                return out;
            c4 = base64decodechars[c4];
        } while (i < len && c4 == -1);
        if (c4 == -1)
            break;
        out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}

function utf16to8(str) {
    var out, i, len, c;
    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007f)) {
            out += str.charAt(i);
        } else if (c > 0x07ff) {
            out += String.fromCharCode(0xe0 | ((c >> 12) & 0x0f));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3f));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
        } else {
            out += String.fromCharCode(0xc0 | ((c >> 6) & 0x1f));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
        }
    }
    return out;
}

function utf8to16(str) {
    var out, i, len, c;
    var char2, char3;

    out = "";
    len = str.length;
    i = 0;
    while (i < len) {
        c = str.charCodeAt(i++);
        switch (c >> 4) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
                // 0xxxxxxx
                out += str.charAt(i - 1);
                break;
            case 12:
            case 13:
                // 110x xxxx   10xx xxxx
                char2 = str.charCodeAt(i++);
                out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
                break;
            case 14:
                // 1110 xxxx  10xx xxxx  10xx xxxx
                char2 = str.charCodeAt(i++);
                char3 = str.charCodeAt(i++);
                out += String.fromCharCode(((c & 0x0f) << 12) |
                    ((char2 & 0x3f) << 6) |
                    ((char3 & 0x3f) << 0));
                break;
        }
    }

    return out;
}﻿ //var bigInt = function (undefined) { "use strict"; var BASE = 1e7, LOG_BASE = 7, MAX_INT = 9007199254740992, MAX_INT_ARR = smallToArray(MAX_INT), LOG_MAX_INT = Math.log(MAX_INT); function Integer(v, radix) { if (typeof v === "undefined") return Integer[0]; if (typeof radix !== "undefined") return +radix === 10 ? parseValue(v) : parseBase(v, radix); return parseValue(v) } function BigInteger(value, sign) { this.value = value; this.sign = sign; this.isSmall = false } BigInteger.prototype = Object.create(Integer.prototype); function SmallInteger(value) { this.value = value; this.sign = value < 0; this.isSmall = true } SmallInteger.prototype = Object.create(Integer.prototype); function isPrecise(n) { return -MAX_INT < n && n < MAX_INT } function smallToArray(n) { if (n < 1e7) return [n]; if (n < 1e14) return [n % 1e7, Math.floor(n / 1e7)]; return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)] } function arrayToSmall(arr) { trim(arr); var length = arr.length; if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) { switch (length) { case 0: return 0; case 1: return arr[0]; case 2: return arr[0] + arr[1] * BASE; default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE } } return arr } function trim(v) { var i = v.length; while (v[--i] === 0); v.length = i + 1 } function createArray(length) { var x = new Array(length); var i = -1; while (++i < length) { x[i] = 0 } return x } function truncate(n) { if (n > 0) return Math.floor(n); return Math.ceil(n) } function add(a, b) { var l_a = a.length, l_b = b.length, r = new Array(l_a), carry = 0, base = BASE, sum, i; for (i = 0; i < l_b; i++) { sum = a[i] + b[i] + carry; carry = sum >= base ? 1 : 0; r[i] = sum - carry * base } while (i < l_a) { sum = a[i] + carry; carry = sum === base ? 1 : 0; r[i++] = sum - carry * base } if (carry > 0) r.push(carry); return r } function addAny(a, b) { if (a.length >= b.length) return add(a, b); return add(b, a) } function addSmall(a, carry) { var l = a.length, r = new Array(l), base = BASE, sum, i; for (i = 0; i < l; i++) { sum = a[i] - base + carry; carry = Math.floor(sum / base); r[i] = sum - carry * base; carry += 1 } while (carry > 0) { r[i++] = carry % base; carry = Math.floor(carry / base) } return r } BigInteger.prototype.add = function (v) { var n = parseValue(v); if (this.sign !== n.sign) { return this.subtract(n.negate()) } var a = this.value, b = n.value; if (n.isSmall) { return new BigInteger(addSmall(a, Math.abs(b)), this.sign) } return new BigInteger(addAny(a, b), this.sign) }; BigInteger.prototype.plus = BigInteger.prototype.add; SmallInteger.prototype.add = function (v) { var n = parseValue(v); var a = this.value; if (a < 0 !== n.sign) { return this.subtract(n.negate()) } var b = n.value; if (n.isSmall) { if (isPrecise(a + b)) return new SmallInteger(a + b); b = smallToArray(Math.abs(b)) } return new BigInteger(addSmall(b, Math.abs(a)), a < 0) }; SmallInteger.prototype.plus = SmallInteger.prototype.add; function subtract(a, b) { var a_l = a.length, b_l = b.length, r = new Array(a_l), borrow = 0, base = BASE, i, difference; for (i = 0; i < b_l; i++) { difference = a[i] - borrow - b[i]; if (difference < 0) { difference += base; borrow = 1 } else borrow = 0; r[i] = difference } for (i = b_l; i < a_l; i++) { difference = a[i] - borrow; if (difference < 0) difference += base; else { r[i++] = difference; break } r[i] = difference } for (; i < a_l; i++) { r[i] = a[i] } trim(r); return r } function subtractAny(a, b, sign) { var value; if (compareAbs(a, b) >= 0) { value = subtract(a, b) } else { value = subtract(b, a); sign = !sign } value = arrayToSmall(value); if (typeof value === "number") { if (sign) value = -value; return new SmallInteger(value) } return new BigInteger(value, sign) } function subtractSmall(a, b, sign) { var l = a.length, r = new Array(l), carry = -b, base = BASE, i, difference; for (i = 0; i < l; i++) { difference = a[i] + carry; carry = Math.floor(difference / base); difference %= base; r[i] = difference < 0 ? difference + base : difference } r = arrayToSmall(r); if (typeof r === "number") { if (sign) r = -r; return new SmallInteger(r) } return new BigInteger(r, sign) } BigInteger.prototype.subtract = function (v) { var n = parseValue(v); if (this.sign !== n.sign) { return this.add(n.negate()) } var a = this.value, b = n.value; if (n.isSmall) return subtractSmall(a, Math.abs(b), this.sign); return subtractAny(a, b, this.sign) }; BigInteger.prototype.minus = BigInteger.prototype.subtract; SmallInteger.prototype.subtract = function (v) { var n = parseValue(v); var a = this.value; if (a < 0 !== n.sign) { return this.add(n.negate()) } var b = n.value; if (n.isSmall) { return new SmallInteger(a - b) } return subtractSmall(b, Math.abs(a), a >= 0) }; SmallInteger.prototype.minus = SmallInteger.prototype.subtract; BigInteger.prototype.negate = function () { return new BigInteger(this.value, !this.sign) }; SmallInteger.prototype.negate = function () { var sign = this.sign; var small = new SmallInteger(-this.value); small.sign = !sign; return small }; BigInteger.prototype.abs = function () { return new BigInteger(this.value, false) }; SmallInteger.prototype.abs = function () { return new SmallInteger(Math.abs(this.value)) }; function multiplyLong(a, b) { var a_l = a.length, b_l = b.length, l = a_l + b_l, r = createArray(l), base = BASE, product, carry, i, a_i, b_j; for (i = 0; i < a_l; ++i) { a_i = a[i]; for (var j = 0; j < b_l; ++j) { b_j = b[j]; product = a_i * b_j + r[i + j]; carry = Math.floor(product / base); r[i + j] = product - carry * base; r[i + j + 1] += carry } } trim(r); return r } function multiplySmall(a, b) { var l = a.length, r = new Array(l), base = BASE, carry = 0, product, i; for (i = 0; i < l; i++) { product = a[i] * b + carry; carry = Math.floor(product / base); r[i] = product - carry * base } while (carry > 0) { r[i++] = carry % base; carry = Math.floor(carry / base) } return r } function shiftLeft(x, n) { var r = []; while (n-- > 0) r.push(0); return r.concat(x) } function multiplyKaratsuba(x, y) { var n = Math.max(x.length, y.length); if (n <= 30) return multiplyLong(x, y); n = Math.ceil(n / 2); var b = x.slice(n), a = x.slice(0, n), d = y.slice(n), c = y.slice(0, n); var ac = multiplyKaratsuba(a, c), bd = multiplyKaratsuba(b, d), abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d)); var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n)); trim(product); return product } function useKaratsuba(l1, l2) { return -.012 * l1 - .012 * l2 + 15e-6 * l1 * l2 > 0 } BigInteger.prototype.multiply = function (v) { var n = parseValue(v), a = this.value, b = n.value, sign = this.sign !== n.sign, abs; if (n.isSmall) { if (b === 0) return Integer[0]; if (b === 1) return this; if (b === -1) return this.negate(); abs = Math.abs(b); if (abs < BASE) { return new BigInteger(multiplySmall(a, abs), sign) } b = smallToArray(abs) } if (useKaratsuba(a.length, b.length)) return new BigInteger(multiplyKaratsuba(a, b), sign); return new BigInteger(multiplyLong(a, b), sign) }; BigInteger.prototype.times = BigInteger.prototype.multiply; function multiplySmallAndArray(a, b, sign) { if (a < BASE) { return new BigInteger(multiplySmall(b, a), sign) } return new BigInteger(multiplyLong(b, smallToArray(a)), sign) } SmallInteger.prototype._multiplyBySmall = function (a) { if (isPrecise(a.value * this.value)) { return new SmallInteger(a.value * this.value) } return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign) }; BigInteger.prototype._multiplyBySmall = function (a) { if (a.value === 0) return Integer[0]; if (a.value === 1) return this; if (a.value === -1) return this.negate(); return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign) }; SmallInteger.prototype.multiply = function (v) { return parseValue(v)._multiplyBySmall(this) }; SmallInteger.prototype.times = SmallInteger.prototype.multiply; function square(a) { var l = a.length, r = createArray(l + l), base = BASE, product, carry, i, a_i, a_j; for (i = 0; i < l; i++) { a_i = a[i]; carry = 0 - a_i * a_i; for (var j = i; j < l; j++) { a_j = a[j]; product = 2 * (a_i * a_j) + r[i + j] + carry; carry = Math.floor(product / base); r[i + j] = product - carry * base } r[i + l] = carry } trim(r); return r } BigInteger.prototype.square = function () { return new BigInteger(square(this.value), false) }; SmallInteger.prototype.square = function () { var value = this.value * this.value; if (isPrecise(value)) return new SmallInteger(value); return new BigInteger(square(smallToArray(Math.abs(this.value))), false) }; function divMod1(a, b) { var a_l = a.length, b_l = b.length, base = BASE, result = createArray(b.length), divisorMostSignificantDigit = b[b_l - 1], lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)), remainder = multiplySmall(a, lambda), divisor = multiplySmall(b, lambda), quotientDigit, shift, carry, borrow, i, l, q; if (remainder.length <= a_l) remainder.push(0); divisor.push(0); divisorMostSignificantDigit = divisor[b_l - 1]; for (shift = a_l - b_l; shift >= 0; shift--) { quotientDigit = base - 1; if (remainder[shift + b_l] !== divisorMostSignificantDigit) { quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit) } carry = 0; borrow = 0; l = divisor.length; for (i = 0; i < l; i++) { carry += quotientDigit * divisor[i]; q = Math.floor(carry / base); borrow += remainder[shift + i] - (carry - q * base); carry = q; if (borrow < 0) { remainder[shift + i] = borrow + base; borrow = -1 } else { remainder[shift + i] = borrow; borrow = 0 } } while (borrow !== 0) { quotientDigit -= 1; carry = 0; for (i = 0; i < l; i++) { carry += remainder[shift + i] - base + divisor[i]; if (carry < 0) { remainder[shift + i] = carry + base; carry = 0 } else { remainder[shift + i] = carry; carry = 1 } } borrow += carry } result[shift] = quotientDigit } remainder = divModSmall(remainder, lambda)[0]; return [arrayToSmall(result), arrayToSmall(remainder)] } function divMod2(a, b) { var a_l = a.length, b_l = b.length, result = [], part = [], base = BASE, guess, xlen, highx, highy, check; while (a_l) { part.unshift(a[--a_l]); trim(part); if (compareAbs(part, b) < 0) { result.push(0); continue } xlen = part.length; highx = part[xlen - 1] * base + part[xlen - 2]; highy = b[b_l - 1] * base + b[b_l - 2]; if (xlen > b_l) { highx = (highx + 1) * base } guess = Math.ceil(highx / highy); do { check = multiplySmall(b, guess); if (compareAbs(check, part) <= 0) break; guess-- } while (guess); result.push(guess); part = subtract(part, check) } result.reverse(); return [arrayToSmall(result), arrayToSmall(part)] } function divModSmall(value, lambda) { var length = value.length, quotient = createArray(length), base = BASE, i, q, remainder, divisor; remainder = 0; for (i = length - 1; i >= 0; --i) { divisor = remainder * base + value[i]; q = truncate(divisor / lambda); remainder = divisor - q * lambda; quotient[i] = q | 0 } return [quotient, remainder | 0] } function divModAny(self, v) { var value, n = parseValue(v); var a = self.value, b = n.value; var quotient; if (b === 0) throw new Error("Cannot divide by zero"); if (self.isSmall) { if (n.isSmall) { return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)] } return [Integer[0], self] } if (n.isSmall) { if (b === 1) return [self, Integer[0]]; if (b == -1) return [self.negate(), Integer[0]]; var abs = Math.abs(b); if (abs < BASE) { value = divModSmall(a, abs); quotient = arrayToSmall(value[0]); var remainder = value[1]; if (self.sign) remainder = -remainder; if (typeof quotient === "number") { if (self.sign !== n.sign) quotient = -quotient; return [new SmallInteger(quotient), new SmallInteger(remainder)] } return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)] } b = smallToArray(abs) } var comparison = compareAbs(a, b); if (comparison === -1) return [Integer[0], self]; if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]]; if (a.length + b.length <= 200) value = divMod1(a, b); else value = divMod2(a, b); quotient = value[0]; var qSign = self.sign !== n.sign, mod = value[1], mSign = self.sign; if (typeof quotient === "number") { if (qSign) quotient = -quotient; quotient = new SmallInteger(quotient) } else quotient = new BigInteger(quotient, qSign); if (typeof mod === "number") { if (mSign) mod = -mod; mod = new SmallInteger(mod) } else mod = new BigInteger(mod, mSign); return [quotient, mod] } BigInteger.prototype.divmod = function (v) { var result = divModAny(this, v); return { quotient: result[0], remainder: result[1] } }; SmallInteger.prototype.divmod = BigInteger.prototype.divmod; BigInteger.prototype.divide = function (v) { return divModAny(this, v)[0] }; SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide; BigInteger.prototype.mod = function (v) { return divModAny(this, v)[1] }; SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod; BigInteger.prototype.pow = function (v) { var n = parseValue(v), a = this.value, b = n.value, value, x, y; if (b === 0) return Integer[1]; if (a === 0) return Integer[0]; if (a === 1) return Integer[1]; if (a === -1) return n.isEven() ? Integer[1] : Integer[-1]; if (n.sign) { return Integer[0] } if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large."); if (this.isSmall) { if (isPrecise(value = Math.pow(a, b))) return new SmallInteger(truncate(value)) } x = this; y = Integer[1]; while (true) { if (b & 1 === 1) { y = y.times(x); --b } if (b === 0) break; b /= 2; x = x.square() } return y }; SmallInteger.prototype.pow = BigInteger.prototype.pow; BigInteger.prototype.modPow = function (exp, mod) { exp = parseValue(exp); mod = parseValue(mod); if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0"); var r = Integer[1], base = this.mod(mod); while (exp.isPositive()) { if (base.isZero()) return Integer[0]; if (exp.isOdd()) r = r.multiply(base).mod(mod); exp = exp.divide(2); base = base.square().mod(mod) } return r }; SmallInteger.prototype.modPow = BigInteger.prototype.modPow; function compareAbs(a, b) { if (a.length !== b.length) { return a.length > b.length ? 1 : -1 } for (var i = a.length - 1; i >= 0; i--) { if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1 } return 0 } BigInteger.prototype.compareAbs = function (v) { var n = parseValue(v), a = this.value, b = n.value; if (n.isSmall) return 1; return compareAbs(a, b) }; SmallInteger.prototype.compareAbs = function (v) { var n = parseValue(v), a = Math.abs(this.value), b = n.value; if (n.isSmall) { b = Math.abs(b); return a === b ? 0 : a > b ? 1 : -1 } return -1 }; BigInteger.prototype.compare = function (v) { if (v === Infinity) { return -1 } if (v === -Infinity) { return 1 } var n = parseValue(v), a = this.value, b = n.value; if (this.sign !== n.sign) { return n.sign ? 1 : -1 } if (n.isSmall) { return this.sign ? -1 : 1 } return compareAbs(a, b) * (this.sign ? -1 : 1) }; BigInteger.prototype.compareTo = BigInteger.prototype.compare; SmallInteger.prototype.compare = function (v) { if (v === Infinity) { return -1 } if (v === -Infinity) { return 1 } var n = parseValue(v), a = this.value, b = n.value; if (n.isSmall) { return a == b ? 0 : a > b ? 1 : -1 } if (a < 0 !== n.sign) { return a < 0 ? -1 : 1 } return a < 0 ? 1 : -1 }; SmallInteger.prototype.compareTo = SmallInteger.prototype.compare; BigInteger.prototype.equals = function (v) { return this.compare(v) === 0 }; SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals; BigInteger.prototype.notEquals = function (v) { return this.compare(v) !== 0 }; SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals; BigInteger.prototype.greater = function (v) { return this.compare(v) > 0 }; SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater; BigInteger.prototype.lesser = function (v) { return this.compare(v) < 0 }; SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser; BigInteger.prototype.greaterOrEquals = function (v) { return this.compare(v) >= 0 }; SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals; BigInteger.prototype.lesserOrEquals = function (v) { return this.compare(v) <= 0 }; SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals; BigInteger.prototype.isEven = function () { return (this.value[0] & 1) === 0 }; SmallInteger.prototype.isEven = function () { return (this.value & 1) === 0 }; BigInteger.prototype.isOdd = function () { return (this.value[0] & 1) === 1 }; SmallInteger.prototype.isOdd = function () { return (this.value & 1) === 1 }; BigInteger.prototype.isPositive = function () { return !this.sign }; SmallInteger.prototype.isPositive = function () { return this.value > 0 }; BigInteger.prototype.isNegative = function () { return this.sign }; SmallInteger.prototype.isNegative = function () { return this.value < 0 }; BigInteger.prototype.isUnit = function () { return false }; SmallInteger.prototype.isUnit = function () { return Math.abs(this.value) === 1 }; BigInteger.prototype.isZero = function () { return false }; SmallInteger.prototype.isZero = function () { return this.value === 0 }; BigInteger.prototype.isDivisibleBy = function (v) { var n = parseValue(v); var value = n.value; if (value === 0) return false; if (value === 1) return true; if (value === 2) return this.isEven(); return this.mod(n).equals(Integer[0]) }; SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy; function isBasicPrime(v) { var n = v.abs(); if (n.isUnit()) return false; if (n.equals(2) || n.equals(3) || n.equals(5)) return true; if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false; if (n.lesser(25)) return true } BigInteger.prototype.isPrime = function () { var isPrime = isBasicPrime(this); if (isPrime !== undefined) return isPrime; var n = this.abs(), nPrev = n.prev(); var a = [2, 3, 5, 7, 11, 13, 17, 19], b = nPrev, d, t, i, x; while (b.isEven()) b = b.divide(2); for (i = 0; i < a.length; i++) { x = bigInt(a[i]).modPow(b, n); if (x.equals(Integer[1]) || x.equals(nPrev)) continue; for (t = true, d = b; t && d.lesser(nPrev) ; d = d.multiply(2)) { x = x.square().mod(n); if (x.equals(nPrev)) t = false } if (t) return false } return true }; SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime; BigInteger.prototype.isProbablePrime = function (iterations) { var isPrime = isBasicPrime(this); if (isPrime !== undefined) return isPrime; var n = this.abs(); var t = iterations === undefined ? 5 : iterations; for (var i = 0; i < t; i++) { var a = bigInt.randBetween(2, n.minus(2)); if (!a.modPow(n.prev(), n).isUnit()) return false } return true }; SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime; BigInteger.prototype.modInv = function (n) { var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR; while (!newR.equals(bigInt.zero)) { q = r.divide(newR); lastT = t; lastR = r; t = newT; r = newR; newT = lastT.subtract(q.multiply(newT)); newR = lastR.subtract(q.multiply(newR)) } if (!r.equals(1)) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime"); if (t.compare(0) === -1) { t = t.add(n) } if (this.isNegative()) { return t.negate() } return t }; SmallInteger.prototype.modInv = BigInteger.prototype.modInv; BigInteger.prototype.next = function () { var value = this.value; if (this.sign) { return subtractSmall(value, 1, this.sign) } return new BigInteger(addSmall(value, 1), this.sign) }; SmallInteger.prototype.next = function () { var value = this.value; if (value + 1 < MAX_INT) return new SmallInteger(value + 1); return new BigInteger(MAX_INT_ARR, false) }; BigInteger.prototype.prev = function () { var value = this.value; if (this.sign) { return new BigInteger(addSmall(value, 1), true) } return subtractSmall(value, 1, this.sign) }; SmallInteger.prototype.prev = function () { var value = this.value; if (value - 1 > -MAX_INT) return new SmallInteger(value - 1); return new BigInteger(MAX_INT_ARR, true) }; var powersOfTwo = [1]; while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]); var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1]; function shift_isSmall(n) { return (typeof n === "number" || typeof n === "string") && +Math.abs(n) <= BASE || n instanceof BigInteger && n.value.length <= 1 } BigInteger.prototype.shiftLeft = function (n) { if (!shift_isSmall(n)) { throw new Error(String(n) + " is too large for shifting.") } n = +n; if (n < 0) return this.shiftRight(-n); var result = this; if (result.isZero()) return result; while (n >= powers2Length) { result = result.multiply(highestPower2); n -= powers2Length - 1 } return result.multiply(powersOfTwo[n]) }; SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft; BigInteger.prototype.shiftRight = function (n) { var remQuo; if (!shift_isSmall(n)) { throw new Error(String(n) + " is too large for shifting.") } n = +n; if (n < 0) return this.shiftLeft(-n); var result = this; while (n >= powers2Length) { if (result.isZero() || result.isNegative() && result.isUnit()) return result; remQuo = divModAny(result, highestPower2); result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; n -= powers2Length - 1 } remQuo = divModAny(result, powersOfTwo[n]); return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0] }; SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight; function bitwise(x, y, fn) { y = parseValue(y); var xSign = x.isNegative(), ySign = y.isNegative(); var xRem = xSign ? x.not() : x, yRem = ySign ? y.not() : y; var xDigit = 0, yDigit = 0; var xDivMod = null, yDivMod = null; var result = []; while (!xRem.isZero() || !yRem.isZero()) { xDivMod = divModAny(xRem, highestPower2); xDigit = xDivMod[1].toJSNumber(); if (xSign) { xDigit = highestPower2 - 1 - xDigit } yDivMod = divModAny(yRem, highestPower2); yDigit = yDivMod[1].toJSNumber(); if (ySign) { yDigit = highestPower2 - 1 - yDigit } xRem = xDivMod[0]; yRem = yDivMod[0]; result.push(fn(xDigit, yDigit)) } var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0); for (var i = result.length - 1; i >= 0; i -= 1) { sum = sum.multiply(highestPower2).add(bigInt(result[i])) } return sum } BigInteger.prototype.not = function () { return this.negate().prev() }; SmallInteger.prototype.not = BigInteger.prototype.not; BigInteger.prototype.and = function (n) { return bitwise(this, n, function (a, b) { return a & b }) }; SmallInteger.prototype.and = BigInteger.prototype.and; BigInteger.prototype.or = function (n) { return bitwise(this, n, function (a, b) { return a | b }) }; SmallInteger.prototype.or = BigInteger.prototype.or; BigInteger.prototype.xor = function (n) { return bitwise(this, n, function (a, b) { return a ^ b }) }; SmallInteger.prototype.xor = BigInteger.prototype.xor; var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I; function roughLOB(n) { var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : v[0] + v[1] * BASE | LOBMASK_BI; return x & -x } function integerLogarithm(value, base) { if (base.compareTo(value) <= 0) { var tmp = integerLogarithm(value, base.square(base)); var p = tmp.p; var e = tmp.e; var t = p.multiply(base); return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p: p, e: e * 2 } } return { p: bigInt(1), e: 0 } } BigInteger.prototype.bitLength = function () { var n = this; if (n.compareTo(bigInt(0)) < 0) { n = n.negate().subtract(bigInt(1)) } if (n.compareTo(bigInt(0)) === 0) { return bigInt(0) } return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1)) }; SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength; function max(a, b) { a = parseValue(a); b = parseValue(b); return a.greater(b) ? a : b } function min(a, b) { a = parseValue(a); b = parseValue(b); return a.lesser(b) ? a : b } function gcd(a, b) { a = parseValue(a).abs(); b = parseValue(b).abs(); if (a.equals(b)) return a; if (a.isZero()) return b; if (b.isZero()) return a; var c = Integer[1], d, t; while (a.isEven() && b.isEven()) { d = Math.min(roughLOB(a), roughLOB(b)); a = a.divide(d); b = b.divide(d); c = c.multiply(d) } while (a.isEven()) { a = a.divide(roughLOB(a)) } do { while (b.isEven()) { b = b.divide(roughLOB(b)) } if (a.greater(b)) { t = b; b = a; a = t } b = b.subtract(a) } while (!b.isZero()); return c.isUnit() ? a : a.multiply(c) } function lcm(a, b) { a = parseValue(a).abs(); b = parseValue(b).abs(); return a.divide(gcd(a, b)).multiply(b) } function randBetween(a, b) { a = parseValue(a); b = parseValue(b); var low = min(a, b), high = max(a, b); var range = high.subtract(low).add(1); if (range.isSmall) return low.add(Math.floor(Math.random() * range)); var length = range.value.length - 1; var result = [], restricted = true; for (var i = length; i >= 0; i--) { var top = restricted ? range.value[i] : BASE; var digit = truncate(Math.random() * top); result.unshift(digit); if (digit < top) restricted = false } result = arrayToSmall(result); return low.add(typeof result === "number" ? new SmallInteger(result) : new BigInteger(result, false)) } var parseBase = function (text, base) { var length = text.length; var i; var absBase = Math.abs(base); for (var i = 0; i < length; i++) { var c = text[i].toLowerCase(); if (c === "-") continue; if (/[a-z0-9]/.test(c)) { if (/[0-9]/.test(c) && +c >= absBase) { if (c === "1" && absBase === 1) continue; throw new Error(c + " is not a valid digit in base " + base + ".") } else if (c.charCodeAt(0) - 87 >= absBase) { throw new Error(c + " is not a valid digit in base " + base + ".") } } } if (2 <= base && base <= 36) { if (length <= LOG_MAX_INT / Math.log(base)) { var result = parseInt(text, base); if (isNaN(result)) { throw new Error(c + " is not a valid digit in base " + base + ".") } return new SmallInteger(parseInt(text, base)) } } base = parseValue(base); var digits = []; var isNegative = text[0] === "-"; for (i = isNegative ? 1 : 0; i < text.length; i++) { var c = text[i].toLowerCase(), charCode = c.charCodeAt(0); if (48 <= charCode && charCode <= 57) digits.push(parseValue(c)); else if (97 <= charCode && charCode <= 122) digits.push(parseValue(c.charCodeAt(0) - 87)); else if (c === "<") { var start = i; do { i++ } while (text[i] !== ">"); digits.push(parseValue(text.slice(start + 1, i))) } else throw new Error(c + " is not a valid character") } return parseBaseFromArray(digits, base, isNegative) }; function parseBaseFromArray(digits, base, isNegative) { var val = Integer[0], pow = Integer[1], i; for (i = digits.length - 1; i >= 0; i--) { val = val.add(digits[i].times(pow)); pow = pow.times(base) } return isNegative ? val.negate() : val } function stringify(digit) { if (digit <= 35) { return "0123456789abcdefghijklmnopqrstuvwxyz".charAt(digit) } return "<" + digit + ">" } function toBase(n, base) { base = bigInt(base); if (base.isZero()) { if (n.isZero()) return { value: [0], isNegative: false }; throw new Error("Cannot convert nonzero numbers to base 0.") } if (base.equals(-1)) { if (n.isZero()) return { value: [0], isNegative: false }; if (n.isNegative()) return { value: [].concat.apply([], Array.apply(null, Array(-n)).map(Array.prototype.valueOf, [1, 0])), isNegative: false }; var arr = Array.apply(null, Array(+n - 1)).map(Array.prototype.valueOf, [0, 1]); arr.unshift([1]); return { value: [].concat.apply([], arr), isNegative: false } } var neg = false; if (n.isNegative() && base.isPositive()) { neg = true; n = n.abs() } if (base.equals(1)) { if (n.isZero()) return { value: [0], isNegative: false }; return { value: Array.apply(null, Array(+n)).map(Number.prototype.valueOf, 1), isNegative: neg } } var out = []; var left = n, divmod; while (left.isNegative() || left.compareAbs(base) >= 0) { divmod = left.divmod(base); left = divmod.quotient; var digit = divmod.remainder; if (digit.isNegative()) { digit = base.minus(digit).abs(); left = left.next() } out.push(digit.toJSNumber()) } out.push(left.toJSNumber()); return { value: out.reverse(), isNegative: neg } } function toBaseString(n, base) { var arr = toBase(n, base); return (arr.isNegative ? "-" : "") + arr.value.map(stringify).join("") } BigInteger.prototype.toArray = function (radix) { return toBase(this, radix) }; SmallInteger.prototype.toArray = function (radix) { return toBase(this, radix) }; BigInteger.prototype.toString = function (radix) { if (radix === undefined) radix = 10; if (radix !== 10) return toBaseString(this, radix); var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit; while (--l >= 0) { digit = String(v[l]); str += zeros.slice(digit.length) + digit } var sign = this.sign ? "-" : ""; return sign + str }; SmallInteger.prototype.toString = function (radix) { if (radix === undefined) radix = 10; if (radix != 10) return toBaseString(this, radix); return String(this.value) }; BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function () { return this.toString() }; BigInteger.prototype.valueOf = function () { return parseInt(this.toString(), 10) }; BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf; SmallInteger.prototype.valueOf = function () { return this.value }; SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf; function parseStringValue(v) { if (isPrecise(+v)) { var x = +v; if (x === truncate(x)) return new SmallInteger(x); throw new Error("Invalid integer: " + v) } var sign = v[0] === "-"; if (sign) v = v.slice(1); var split = v.split(/e/i); if (split.length > 2) throw new Error("Invalid integer: " + split.join("e")); if (split.length === 2) { var exp = split[1]; if (exp[0] === "+") exp = exp.slice(1); exp = +exp; if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent."); var text = split[0]; var decimalPlace = text.indexOf("."); if (decimalPlace >= 0) { exp -= text.length - decimalPlace - 1; text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1) } if (exp < 0) throw new Error("Cannot include negative exponent part for integers"); text += new Array(exp + 1).join("0"); v = text } var isValid = /^([0-9][0-9]*)$/.test(v); if (!isValid) throw new Error("Invalid integer: " + v); var r = [], max = v.length, l = LOG_BASE, min = max - l; while (max > 0) { r.push(+v.slice(min, max)); min -= l; if (min < 0) min = 0; max -= l } trim(r); return new BigInteger(r, sign) } function parseNumberValue(v) { if (isPrecise(v)) { if (v !== truncate(v)) throw new Error(v + " is not an integer."); return new SmallInteger(v) } return parseStringValue(v.toString()) } function parseValue(v) { if (typeof v === "number") { return parseNumberValue(v) } if (typeof v === "string") { return parseStringValue(v) } return v } for (var i = 0; i < 1e3; i++) { Integer[i] = new SmallInteger(i); if (i > 0) Integer[-i] = new SmallInteger(-i) } Integer.one = Integer[1]; Integer.zero = Integer[0]; Integer.minusOne = Integer[-1]; Integer.max = max; Integer.min = min; Integer.gcd = gcd; Integer.lcm = lcm; Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger }; Integer.randBetween = randBetween; Integer.fromArray = function (digits, base, isNegative) { return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative) }; return Integer }(); if (typeof module !== "undefined" && module.hasOwnProperty("exports")) { module.exports = bigInt } if (typeof define === "function" && define.amd) { define("big-integer", [], function () { return bigInt }) }

//表示全局唯一标识符 (GUID)。

function Guid(g) {

    var arr = new Array(); //存放32位数值的数组
    if (typeof(g) == "string") { //如果构造函数的参数为字符串
        InitByString(arr, g);
    } else {
        InitByOther(arr);
    }
    //返回一个值，该值指示 Guid 的两个实例是否表示同一个值。
    this.Equals = function(o) {
        if (o && o.IsGuid) {
            return this.ToString() == o.ToString();
        } else {
            return false;
        }
    };

    //Guid对象的标记
    this.IsGuid = function() {};
    //返回 Guid 类的此实例值的 String 表示形式。
    this.ToString = function(format) {
        if (typeof(format) == "string") {
            if (format == "N" || format == "D" || format == "B" || format == "P") {
                return ToStringWithFormat(arr, format);
            } else {
                return ToStringWithFormat(arr, "D");
            }
        } else {
            return ToStringWithFormat(arr, "D");
        }
    };
    //由字符串加载
    function InitByString(arr, g) {
        g = g.replace(/\{|\(|\)|\}|-/g, "");
        g = g.toLowerCase();
        if (g.length != 32 || g.search(/[^0-9,a-f]/i) != -1) {
            InitByOther(arr);
        } else {
            for (var i = 0; i < g.length; i++) {
                arr.push(g[i] || g.charAt(i));
            }
        }
    }
    //由其他类型加载
    function InitByOther(arr) {
        var i = 32;
        while (i--) {
            arr.push("0");
        }
    }
    /*
    根据所提供的格式说明符，返回此 Guid 实例值的 String 表示形式。
    N  32 位： xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    D  由连字符分隔的 32 位数字 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
    B  括在大括号中、由连字符分隔的 32 位数字：{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 
    P  括在圆括号中、由连字符分隔的 32 位数字：(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) 
    */
    function ToStringWithFormat(arr, format) {
        switch (format) {
            case "N":
                return arr.toString().replace(/,/g, "");
            case "D":
                var str = arr.slice(0, 8) + "-" + arr.slice(8, 12) + "-" + arr.slice(12, 16) + "-" + arr.slice(16, 20) + "-" + arr.slice(20, 32);
                str = str.replace(/,/g, "");
                return str;
            case "B":
                var str = ToStringWithFormat(arr, "D");
                str = "{" + str + "}";
                return str;
            case "P":
                var str = ToStringWithFormat(arr, "D");
                str = "(" + str + ")";
                return str;
            default:
                return new Guid();
        }
    }
}

//function Snowflake(_workerId, _dataCenterId, _sequence) {
//    // this.twepoch = 1288834974657;
//    this.twepoch = 0;
//    this.workerIdBits = 5;
//    this.dataCenterIdBits = 5;
//    this.maxWrokerId = -1 ^ (-1 << this.workerIdBits); // 值为：31
//    this.maxDataCenterId = -1 ^ (-1 << this.dataCenterIdBits); // 值为：31
//    this.sequenceBits = 12;
//    this.workerIdShift = this.sequenceBits; // 值为：12
//    this.dataCenterIdShift = this.sequenceBits + this.workerIdBits; // 值为：17
//    this.timestampLeftShift = this.sequenceBits + this.workerIdBits + this.dataCenterIdBits; // 值为：22
//    this.sequenceMask = -1 ^ (-1 << this.sequenceBits); // 值为：4095
//    this.lastTimestamp = -1;
//    //设置默认值,从环境变量取
//    this.workerId = 1;
//    this.dataCenterId = 1;
//    this.sequence = 0;
//    this.workerId = _workerId;
//    this.dataCenterId = _dataCenterId;
//    this.sequence = _sequence;
//    if (this.workerId > this.maxWrokerId || this.workerId < 0) {
//        throw new Error('config.worker_id must max than 0 and small than maxWrokerId-[' + this.maxWrokerId + ']');
//    }
//    if (this.dataCenterId > this.maxDataCenterId || this.dataCenterId < 0) {
//        throw new Error('config.data_center_id must max than 0 and small than maxDataCenterId-[' + this.maxDataCenterId + ']');
//    }
//}
//Snowflake.prototype.tilNextMillis = function (lastTimestamp) {
//    var timestamp = this.timeGen();
//    while (timestamp <= lastTimestamp) {
//        timestamp = this.timeGen();
//    }
//    return timestamp;
//};
//Snowflake.prototype.timeGen = function () {
//    //new Date().getTime() === Date.now()
//    return Date.now();
//};
//Snowflake.prototype.ToString = function () {
//    var timestamp = this.timeGen();
//    if (timestamp < this.lastTimestamp) {
//        throw new Error('Clock moved backwards. Refusing to generate id for ' +
//            (this.lastTimestamp - timestamp));
//    }
//    if (this.lastTimestamp === timestamp) {
//        this.sequence = (this.sequence + 1) & this.sequenceMask;
//        if (this.sequence === 0) {
//            timestamp = this.tilNextMillis(this.lastTimestamp);
//        }
//    } else {
//        this.sequence = 0;
//    }
//    this.lastTimestamp = timestamp;
//    var shiftNum = (this.dataCenterId << this.dataCenterIdShift) |
//        (this.workerId << this.workerIdShift) |
//        this.sequence; // dataCenterId:1,workerId:1,sequence:0  shiftNum:135168
//    var nfirst = new bigInt(String(timestamp - this.twepoch), 10);
//    nfirst = nfirst.shiftLeft(this.timestampLeftShift);
//    var nnextId = nfirst.or(new bigInt(String(shiftNum), 10)).toString(10);
//    return nnextId;
//};
//
//var tempSnowflake = new Snowflake(1, 1, 0);


//Guid 类的默认实例，其值保证均为零。
Guid.Empty = new Guid();
//初始化 Guid 类的一个新实例。
Guid.NewGuid = function() {
    if (typeof GSIDPSession !== 'undefined' && GSIDPSession.SiteConfig && GSIDPSession.SiteConfig.EnableSnowFlake) {
        var vsval = "";
        var vsJsonData = { "type": "GUID" };
        $.ajax({
            url: "../../GSYS/web/ashx/GetWebSvrParam.ashx",
            type: "post",
            dataType: "text",
            data: vsJsonData,
            async: false,
            success: function(reval) {
                vsval = reval;
            },
            error: function(err) {
                throw err.responseText;
            }
        });
        return {
            ToString: function() {
                return vsval;
            }
        };
        // return tempSnowflake;
    }
    var g = "";
    var i = 32;
    while (i--) {
        g += Math.floor(Math.random() * 16.0).toString(16);
    }
    return new Guid(g);
};﻿
/*
    http://www.JSON.org/json2.js
    2010-11-17

    Public Domain.

    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.

    See http://www.JSON.org/js.html


    This code should be minified before deployment.
    See http://javascript.crockford.com/jsmin.html

    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
    NOT CONTROL.


    This file creates a global JSON object containing two methods: stringify
    and parse.

        JSON.stringify(value, replacer, space)
            value       any JavaScript value, usually an object or array.

            replacer    an optional parameter that determines how object
                        values are stringified for objects. It can be a
                        function or an array of strings.

            space       an optional parameter that specifies the indentation
                        of nested structures. If it is omitted, the text will
                        be packed without extra whitespace. If it is a number,
                        it will specify the number of spaces to indent at each
                        level. If it is a string (such as '\t' or '&nbsp;'),
                        it contains the characters used to indent at each level.

            This method produces a JSON text from a JavaScript value.

            When an object value is found, if the object contains a toJSON
            method, its toJSON method will be called and the result will be
            stringified. A toJSON method does not serialize: it returns the
            value represented by the name/value pair that should be serialized,
            or undefined if nothing should be serialized. The toJSON method
            will be passed the key associated with the value, and this will be
            bound to the value

            For example, this would serialize Dates as ISO strings.

                Date.prototype.toJSON = function (key) {
                    function f(n) {
                        // Format integers to have at least two digits.
                        return n < 10 ? '0' + n : n;
                    }

                    return this.getUTCFullYear()   + '-' +
                         f(this.getUTCMonth() + 1) + '-' +
                         f(this.getUTCDate())      + 'T' +
                         f(this.getUTCHours())     + ':' +
                         f(this.getUTCMinutes())   + ':' +
                         f(this.getUTCSeconds())   + 'Z';
                };

            You can provide an optional replacer method. It will be passed the
            key and value of each member, with this bound to the containing
            object. The value that is returned from your method will be
            serialized. If your method returns undefined, then the member will
            be excluded from the serialization.

            If the replacer parameter is an array of strings, then it will be
            used to select the members to be serialized. It filters the results
            such that only members with keys listed in the replacer array are
            stringified.

            Values that do not have JSON representations, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays they will be replaced with null. You can use
            a replacer function to replace those with JSON values.
            JSON.stringify(undefined) returns undefined.

            The optional space parameter produces a stringification of the
            value that is filled with line breaks and indentation to make it
            easier to read.

            If the space parameter is a non-empty string, then that string will
            be used for indentation. If the space parameter is a number, then
            the indentation will be that many spaces.

            Example:

            text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'


            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'

            text = JSON.stringify([new Date()], function (key, value) {
                return this[key] instanceof Date ?
                    'Date(' + this[key] + ')' : value;
            });
            // text is '["Date(---current time---)"]'


        JSON.parse(text, reviver)
            This method parses a JSON text to produce an object or array.
            It can throw a SyntaxError exception.

            The optional reviver parameter is a function that can filter and
            transform the results. It receives each of the keys and values,
            and its return value is used instead of the original value.
            If it returns what it received, then the structure is not modified.
            If it returns undefined then the member is deleted.

            Example:

            // Parse the text. Values that look like ISO date strings will
            // be converted to Date objects.

            myData = JSON.parse(text, function (key, value) {
                var a;
                if (typeof value === 'string') {
                    a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
                    if (a) {
                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
                    }
                }
                return value;
            });

            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
                var d;
                if (typeof value === 'string' &&
                        value.slice(0, 5) === 'Date(' &&
                        value.slice(-1) === ')') {
                    d = new Date(value.slice(5, -1));
                    if (d) {
                        return d;
                    }
                }
                return value;
            });


    This is a reference implementation. You are free to copy, modify, or
    redistribute.
*/

/*jslint evil: true, strict: false, regexp: false */

/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
    lastIndex, length, parse, prototype, push, replace, slice, stringify,
    test, toJSON, toString, valueOf
*/


// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.

if (!this.JSON2) {
    this.JSON2 = {};
}

(function() {
    "use strict";

    function f(n) {
        // Format integers to have at least two digits.
        return n < 10 ? '0' + n : n;
    }

    if (typeof Date.prototype.toJSON !== 'function') {

        Date.prototype.toJSON = function(key) {

            return isFinite(this.valueOf()) ?
                this.getUTCFullYear() + '-' +
                f(this.getUTCMonth() + 1) + '-' +
                f(this.getUTCDate()) + 'T' +
                f(this.getUTCHours()) + ':' +
                f(this.getUTCMinutes()) + ':' +
                f(this.getUTCSeconds()) + 'Z' : null;
        };

        String.prototype.toJSON =
            Number.prototype.toJSON =
            Boolean.prototype.toJSON = function(key) {
                return this.valueOf();
            };
    }

    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = { // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"': '\\"',
            '\\': '\\\\'
        },
        rep;


    function quote(string) {

        escapable.lastIndex = 0;
        return escapable.test(string) ?
            '"' + string.replace(escapable, function(a) {
                var c = meta[a];
                return typeof c === 'string' ? c :
                    '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
            }) + '"' :
            '"' + string + '"';
    }

    function str(key, holder) {
        var i, // The loop counter.
            k, // The member key.
            v, // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];
        if (value && typeof value === 'object' &&
            typeof value.toJSON === 'function') {
            if (value instanceof Date) {

                value =
                    value.getFullYear() + '-' +
                    f(value.getMonth() + 1) + '-' +
                    f(value.getDate()) + 'T' +
                    f(value.getHours()) + ':' +
                    f(value.getMinutes()) + ':' +
                    f(value.getSeconds()) + 'Z';
            } else {
                value = value.toJSON(key);
            }
        }
        if (typeof rep === 'function') {
            value = rep.call(holder, key, value);
        }
        switch (typeof value) {
            case 'string':
                return quote(value);
            case 'number':
                return isFinite(value) ? String(value) : 'null';
            case 'boolean':
            case 'null':
                return String(value);
            case 'object':
                if (!value) {
                    return 'null';
                }
                gap += indent;
                partial = [];
                if (Object.prototype.toString.apply(value) === '[object Array]') {
                    length = value.length;
                    for (i = 0; i < length; i += 1) {
                        partial[i] = str(i, value) || 'null';
                    }
                    v = partial.length === 0 ? '[]' :
                        gap ? '[\n' + gap +
                        partial.join(',\n' + gap) + '\n' +
                        mind + ']' :
                        '[' + partial.join(',') + ']';
                    gap = mind;
                    return v;
                }
                if (rep && typeof rep === 'object') {
                    length = rep.length;
                    for (i = 0; i < length; i += 1) {
                        k = rep[i];
                        if (typeof k === 'string') {
                            v = str(k, value);
                            if (v) {
                                partial.push(quote(k) + (gap ? ': ' : ':') + v);
                            }
                        }
                    }
                } else {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = str(k, value);
                            if (v) {
                                partial.push(quote(k) + (gap ? ': ' : ':') + v);
                            }
                        }
                    }
                }
                v = partial.length === 0 ? '{}' :
                    gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                    mind + '}' : '{' + partial.join(',') + '}';
                gap = mind;
                return v;
        }
    }
    if (typeof JSON2.stringify !== 'function') {
        JSON2.stringify = function(value, replacer, space) {
            var i;
            gap = '';
            indent = '';
            if (typeof space === 'number') {
                for (i = 0; i < space; i += 1) {
                    indent += ' ';
                }
            } else if (typeof space === 'string') {
                indent = space;
            }
            rep = replacer;
            if (replacer && typeof replacer !== 'function' &&
                (typeof replacer !== 'object' ||
                    typeof replacer.length !== 'number')) {
                throw new Error('JSON2.stringify');
            }
            return str('', { '': value });
        };
    }
    if (typeof JSON2.parse !== 'function') {
        JSON2.parse = function(text, reviver) {
            var j;

            function walk(holder, key) {
                var k, v, value = holder[key];
                if (value && typeof value === 'object') {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v;
                            } else {
                                delete value[k];
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value);
            }
            text = String(text);
            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function(a) {
                    return '\\u' +
                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                });
            }
            if (/^[\],:{}\s]*$/
                .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
                    .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
                    .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
                j = eval('(' + text + ')');
                return typeof reviver === 'function' ?
                    walk({ '': j }, '') : j;
            }
            throw new SyntaxError('JSON2.parse');
        };
    }
}());
if (!window.JSON) {
    window.JSON = JSON2;
}

if ($.browser.msie && Number($.browser.version) < 9) {
    window.JSON = JSON2;
} //���ie8�����������  add by liwl 2012-03-16﻿

FormatNumber = function(v, e, type) {
    type = type || "round";
    e = e || 2;
    if (type == "round") {
        return Number(v).toFixed(e);
    } else {
        return Math.floor(Number(v) * Math.pow(10, e)) / Math.pow(10, e);
    }
};

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};
String.prototype.ltrim = function() {
    return this.replace(/(^\s*)/g, "");
};
String.prototype.replaceall = function(strsrc, strd) {
    strd = strd || "";
    var orgstr = this;
    var valstr = "";
    var lenstr = strsrc.length;
    while (orgstr.indexOf(strsrc) != -1) {
        var lint = orgstr.indexOf(strsrc);
        valstr += orgstr.substr(0, lint) + strd;
        orgstr = orgstr.substr(lint + lenstr);
    }
    return valstr + orgstr;
};
String.prototype.rtrim = function() {
    return this.replace(/(\s*$)/g, "");
};
String.prototype.charLongLen = function() {
    return this.replace(/[^\x00-\xff]/g, "**").length;
};
//增加leftpad方法add by liwl 2012/03/28 使用方法 XXX.padleft(7,'0') 即可
String.prototype.padleft = function() {
    var arr = [];
    for (var i = 0; i < arguments[0] - this.length; i++) {
        arr.push(arguments[1]);
    }
    return arr.join('') + this;
};
String.prototype.padright = function() {
    var arr = [];
    for (var i = 0; i < arguments[0] - this.length; i++) {
        arr.push(arguments[1]);
    }
    return this + arr.join('');
};
/*
Date.prototype.toDateLongString = function () {
var vsMonth = this.getMonth() + 1;
if (vsMonth.length == 1) vsMonth = "0" + vsMonth;
var vsday = this.getDay();
if (vsday.length == 1) vsday = "0" + vsday;
var vshour = this.getHours();
if (vshour.length == 1) vshour = "0" + vshour;
var vsmin = this.getMinutes();
if (vsmin.length == 1) vsmin = "0" + vsmin;
var vssec = this.getSeconds();
if (vssec.length == 1) vssec = "00" + vssec;
else  if (vssec.length == 2)  vssec = "0" + vssec;

return this.getFullYear() + "-" + vsMonth + "-" + vsday+" "+vshour +":"+vsmin +":"+vssec;
}*/
/* 不能使用和jquery1.7冲突 不能设置object的属性
Object.prototype.toJsonObjString = function () {
var str = "";
for (var key in this) {
if (key == "toJSONString") continue;
if (!this[key] || this[key] == true) {
str += ",\"" + key + "\":\"" + this[key] + "\"";
} else if (typeof this[key] == "number") {
str += ",\"" + key + "\":\"" + this[key] + "\"";
} else if (typeof this[key] == "string") {
str += ",\"" + key + "\":\"" + this[key] + "\"";
} else if (typeof this[key] == "function") {
str += ",\"" + key + "\":\"" + this[key].toString() + "\"";
} else if (typeof this[key] == "object") {
if (this[key].constructor == Array) {
str += ",\"" + key + "\":" + this[key].toJsonObjString();
} else if (this[key].constructor == Object) {
str += ",\"" + key + "\":" + this[key].toJsonObjString();
}
}

}
return "{" + str.substring(1) + "}";
}


Array.prototype.toJsonObjString = function () {
var str = "";
for (var key = 0; key < this.length; key++) {
if (typeof this[key] == "number") {
str += ",\"" + this[key] + "\"";
} else if (typeof this[key] == "string") {
str += ",\"" + this[key] + "\"";
} else if (!this[key] || this[key] == true) {
str += ",\"" + this[key] + "\"";
} else if (typeof this[key] == "function") {
str += ",\"" + this[key].toString(); +"\"";
} else if (typeof this[key] == "object") {
if (this[key].constructor == Array) {
str += "," + this[key].toJsonObjString();
} else if (this[key].constructor == Date) {
str += "," + this[key].toDateLongString();
} else if (this[key].constructor == Object) {
str += "," + this[key].toJsonObjString();
}
}
}
return "[" + str.substring(1) + "]";
}
*/

String.prototype.jsonFilter = function() {
    return this.replace(/\"/g, "“").replace(/\-\-/g, "－");
    //.replace(/,/g, "，").replace(/\)/g, "）").replace(/\(/g, "（")
    //.replace(/\[/g, "【").replace(/]/g, "】").replace(/{/g, "｛").replace(/}/g, "｝").replace(/#/g, "＃")
    //.replace(/=/g, "＝").replace(/&/g, "＆").replace(/`/g, "·");
    //replace(/\'/g, "‘").先屏蔽
};
/*和jquery1.7冲突，不能设置object的属性
Object.prototype.cloneobj = function () {
if (typeof this == 'number' || typeof this == 'string' || typeof this == 'boolean') {
return this;
}
else if (typeof this == 'object') {
if (this instanceof Array) {
var newArr = [], i, len = json.length;
for (i = 0; i < len; i++) {
newArr[i] = arguments.callee(this[i]);
}
return newArr;
} else {
var newObj = {};
for (var name in this) {
newObj[name] = arguments.callee(this[name]);
}
return newObj;
}
}
}

Object.prototype.clone = function () {
if (this instanceof Array) {
var buf = [];
var i = this.length;
while (i--) {
buf[i] = this[i].clone();
}
return buf;
} else if (this instanceof Object) {
var vsbuf = {};
for (var k in this) {
vsbuf[String(k)] = this[k].clone(); 
}
return vsbuf;
} else {
return this;
}
}
Array.prototype.remove = function (dx) {
if (isNaN(dx) || dx > this.length) { return false; }
for (var i = 0, n = 0; i < this.length; i++) {
if (this[i] != this[dx]) {
this[n++] = this[i]
}
}
this.length -= 1
}
*/
function cloneObject(obj) {
    if (obj instanceof Array) {
        var buf = [];
        var i = obj.length;
        while (i--) {
            buf[i] = cloneObject(obj[i]);
        }
        return buf;
    } else if (obj instanceof Object && typeof obj != 'function') {
        var vsbuf = {};
        for (var k in obj) {
            vsbuf[String(k)] = cloneObject(obj[k]);
        }
        return vsbuf;
    } else {
        return obj;
    }

}

function ArrayContains(arr, e) {
    for (i = 0; i < arr.length; i++) {
        if (arr[i] == e)
            return true;
    }
    return false;
}

function ArrayRemove(arrobj, dx) {
    if (isNaN(dx) || dx > arrobj.length) { return false; }
    for (var i = 0, n = 0; i < arrobj.length; i++) {
        if (arrobj[i] != arrobj[dx]) {
            arrobj[n++] = arrobj[i];
        }
    }
    arrobj.length -= 1;
}

function disponseObject(obj) {
    if (obj != null) {
        obj = null;
        delete obj;
        CollectGarbage();
    }
}
//验证控件方法，
function validControl(checkopts, formid, endGridEditor) {
    var bl = true;
    endGridEditor = endGridEditor == undefined ? true : endGridEditor;
    if (typeof TableProps != "undefined" && TableProps && endGridEditor) {
        for (var key in TableProps) {
            var gridctrl = $("#grid_" + key).ligerGetGridManager();
            if (gridctrl && gridctrl.options && gridctrl.options.clickToEdit && gridctrl.options.enabledEdit) gridctrl.endEdit();
        }
    }
    window.CheckMsg = "";
    if (typeof beforeValidCtrolFunc == 'function') {
        var vsbl = beforeValidCtrolFunc(checkopts, formid);
        if (!vsbl) return vsbl;
    }
    for (var key in checkopts.rules) {
        if (0 == $("#" + key).length || key != $('#' + key).attr('name')) continue;
        var vsbl = $("#" + formid).validate().element($("#" + key));
        if (vsbl == undefined) {
            bl = false; //不能增加break ，否则不能全部验证
        }
        if (vsbl != undefined && !vsbl && bl) {
            bl = vsbl;
        }
    }
    if (window.CheckMsg != "") {
        TipHelp(window.CheckMsg, "", "4000", "warn");
        window.CheckMsg = "";
    } else {
        if (window.ChangeFlag != undefined) window.ChangeFlag = false;
    }
    return bl;
}

//add by upingking 20120312 阻止事件冒泡
function stopBubble(e) {
    if (e && e.stopPropagation)
        e.stopPropagation();
    else
        window.event.cancelBubble = true;
}

function stopEventPropagation() {
    var event = window.event ?
        window.event :
        arguments.callee.caller.arguments[0];
    event.cancelBubble = true;
    event.returnValue = false;
    if (event.preventDefault) {
        event.preventDefault();
    }
    if (event.stopPropagation) {
        event.stopPropagation();
    }
}
var WinOpen = {
    scheight: screen.height - 80,
    scwidth: screen.width - 10,
    FullOpen: function(url, pwidth, pheight) {
        pheight = pheight || this.scheight;
        pwidth = pwidth || this.scwidth;
        var winoption = "left=0,top=0,height=" + pheight + ",width=" + pwidth + ",toolbar=no,menubar=no,location=yes,status=no,scrollbars=auto,resizable=yes";
        var tmp = window.open(url, '', winoption);
        return tmp;
    },
    FullModal: function(url, pwidth, pheight, objparam) {
        pheight = pheight || this.scheight;
        pwidth = pwidth || this.scwidth;
        var winoption = "dialogHeight:" + pheight + "px;dialogWidth:" + pwidth + "px;status:no;menubar:no;location:no;scroll:auto;resizable:yes;center:yes";
        var tmp = window.showModalDialog(url, objparam, winoption);
        return tmp;
    }

};

//tiphelp增加回调函数 add by liwl
function TipHelp(message, title, time, type, callback) { //tooltip提示
    callback = callback || function() {};
    title = title || langobj.get("title");
    time = time || 6000;
    type = type || "success";
    var tip1 = null;
    if (type == "success") {
        tip1 = $.ligerDialog.success(message, title, callback);
    }
    if (type == "warn") {
        tip1 = $.ligerDialog.warn(message, title, callback);
    }
    if (type == "question") {
        tip1 = $.ligerDialog.question(message, title, callback);
    }
    if (type == "error") {
        tip1 = $.ligerDialog.error(message, title, callback);
    }
    //var tip1 = $.ligerDialog.tip({ title: title,width:widthpx,height:heightpx, content: message });
    if (typeof(GSIDPSession) == 'undefined' || typeof(GSIDPSession.IDPCONFIG) == 'undefined' || typeof(GSIDPSession.IDPCONFIG.ISTOAST) == 'undefined' || GSIDPSession.IDPCONFIG.ISTOAST != "false") {
        setTimeout(function() {
            tip1.close();
            //callback();
        }, time);
    }
}

//获取当前属性
function GetCurrentStyle(elobj, prop) {
    if (elobj.currentStyle) {
        return elobj.currentStyle[prop];
    } else if (window.getComputedStyle) {
        propprop = prop.replace(/([A-Z])/g, "-$1");
        propprop = prop.toLowerCase();
        return document.defaultView.getComputedStyle(elobj, null)[prop];
    }
    return null;
}


var __removeDetach = $.extend(window.detachEvent);
window.detachEvent = function(a, b) {
    if (b) {
        __removeDetach(a, b);

    } else {
        __removeDetach(a, function() {});
    }
}


window.onerror = function(message, url, linenumber) {


    if (message.indexOf("缺少对象") != -1 || message.indexOf("Script error") != -1) {
        return;
    }
    if (message.indexOf("ORA-2") != -1) { //自定义oracle提示信息
        msg = message.substr(message.indexOf(":") + 1);
        msg = msg.substr(0, msg.indexOf("ORA-"));
        $.ligerDialog.error(msg, "提示信息");
    } else {
        var msg = langobj.get("error") + message + "<br/>";
        msg += langobj.get("line") + linenumber + "<br/>";
        msg += langobj.get("file") + url;
        $.ligerDialog.open({
            width: 500,
            height: 300,
            type: 'error',
            title: langobj.get("title"),
            content: msg,
            showMax: false,
            showToggle: false,
            showMin: false
        });
    }
    //$.ligerDialog.error(msg, "提示信息"); //{ title: "提示信息", content: msg }

    /*
    if (window.XMLHttpRequest) {
    var xhr = new XMLHttpRequest();
    var scripturl = "http://yourdomain.example.com/log";
        
    xhr.open("POST", scripturl);
    xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
    xhr.send(msg);
    }
    */
    return true;
};



DateFormat = function(date, fmt) {

    if (fmt == null) fmt = "yyyy-MM-dd HH:mm:ss";
    if (typeof date == "string") date = StringToDate(date);
    var o = {
        "M+": date.getMonth() + 1, //月份        
        "d+": date.getDate(), //日        
        "h+": date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, //小时        
        "H+": date.getHours(), //小时        
        "m+": date.getMinutes(), //分        
        "s+": date.getSeconds(), //秒        
        "q+": Math.floor((date.getMonth() + 3) / 3), //季度        
        "S": date.getMilliseconds() //毫秒        
    };
    var week = {
        "0": "\u65e5",
        "1": "\u4e00",
        "2": "\u4e8c",
        "3": "\u4e09",
        "4": "\u56db",
        "5": "\u4e94",
        "6": "\u516d"
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    if (/(E+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "\u661f\u671f" : "\u5468") : "") + week[date.getDay() + ""]);
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};
StringToDate = function(str) {
    if (str instanceof Date) return str;
    var vsre = null;
    if (str != null) {
        str = str.replace(/\-/g, " ").replace(/\:/g, " ");
        var datearr = str.split(' ');
        if (datearr.length > 2) {
            datearr[1] = Number(datearr[1]) - 1;
            var vslen = 6 - datearr.length;
            for (var i = 0; i < vslen; i++)
                datearr.push('00');
        }
        vsre = new Date(datearr[0], datearr[1], datearr[2], datearr[3], datearr[4], datearr[5]);
    }
    return vsre;
};

function TimeCom(dateValue) {
    var newCom;

    if (dateValue == "") {
        newCom = new Date();
    } else {
        newCom = StringToDate(dateValue);
    }
    this.year = newCom.getFullYear();
    this.month = newCom.getMonth() + 1;
    this.day = newCom.getDate();
    this.hour = newCom.getHours();
    this.minute = newCom.getMinutes();
    this.second = newCom.getSeconds();
    this.msecond = newCom.getMilliseconds();
    this.week = newCom.getDay();
}

function DateDiff(interval, date1, date2) {
    if (date1 == '' || date2 == '') {
        return '';
    }
    var TimeCom1 = new TimeCom(date1);
    var TimeCom2 = new TimeCom(date2);
    var result;
    switch (String(interval).toLowerCase()) {
        case "y":
        case "year":
            result = TimeCom1.year - TimeCom2.year;
            break;
        case "m":
        case "month":
            result = (TimeCom1.year - TimeCom2.year) * 12 + (TimeCom1.month - TimeCom2.month);
            break;
        case "d":
        case "day":
            result = 1 + Math.floor((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day)) / (1000 * 60 * 60 * 24));
            break;
        case "h":
        case "hour":
            result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour)) / (1000 * 60 * 60));
            break;
        case "min":
        case "minute":
            result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.minute) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.minute)) / (1000 * 60));
            break;
        case "s":
        case "second":
            result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.minute, TimeCom1.second) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.minute, TimeCom2.second)) / 1000);
            break;
        case "ms":
        case "msecond":
            result = Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day, TimeCom1.hour, TimeCom1.minute, TimeCom1.second, TimeCom1.msecond) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day, TimeCom2.hour, TimeCom2.minute, TimeCom2.second, TimeCom1.msecond);
            break;
        case "w":
        case "week":
            result = Math.round((Date.UTC(TimeCom1.year, TimeCom1.month - 1, TimeCom1.day) - Date.UTC(TimeCom2.year, TimeCom2.month - 1, TimeCom2.day)) / (1000 * 60 * 60 * 24)) % 7;
            break;
        default:
            result = "invalid";
    }
    return (result);
}

function addDays(date, days, type) {
    if (date == "") return "";
    var datearr = date.split("-");
    var d = new Date(datearr[0], datearr[1] - 1, datearr[2]);
    if (d == "Invalid Date") {
        alert("非日期");
        return "";
    }
    var newday = d.getTime() + (days - 1) * 24 * 60 * 60 * 1000;
    var re_day = new Date(newday);
    switch (String(type).toLowerCase()) {
        case "y":
        case "year":
            result = re_day.year
            break;
        case "m":
        case "month":
            result = DateFormat(re_day, 'yyyy-MM'); //re_day.year + "-" + (re_day.month - 1);
            break;
        case "d":
        case "day":
            result = DateFormat(re_day, 'yyyy-MM-dd'); //re_day.year + "-" + (re_day.month - 1) + "-" + (re_day.day);
            break;

        default:
            result = DateFormat(re_day, 'yyyy-MM-dd'); // re_day.year + "-" + (re_day.month - 1) + "-" + (re_day.day);
            break;
    }
    return (result);
}

windowHeight = function() {
    return window.parent == window ? $(window).height() : $(window.parent).height() - 30;
};

window.HelpCrlGetRow = function(pscxid, pswhere, ctrlobj, noauth) {
    /*   function getSqlDefine(cxid) {
    var vssql = Base64.encode("SELECT * FROM GSYQRYLIST WHERE GSYQRYLIST_ID='" + cxid + "'");  //取出帮助的配置信息
    return DealAjax.execSelectSql(null, vssql).Rows;
    }
    if (!Base64) return [];
    var dbsrc = null;
    var vssql = "";
    if (!ctrlobj || !ctrlobj.sql) {
    var Data = getSqlDefine(pscxid);
    if (Data.length <= 0) return [];
    dbsrc = Data[0].GSYQRYLIST_DS;
    var dbtype = DealAjax.execSelectSql(dbsrc, "", "dbtype");
    vssql = Data[0]["GSYQRYLIST_" + (dbtype == "MSS" ? "SQL" : "ORA")];
    if (vssql == "") vssql = Data[0]["GSYQRYLIST_SQL"];
    }
    else { 
    dbsrc = ctrlobj.dbsrc;
    vssql = ctrlobj.sql;
    }
    if (dbsrc == "") dbsrc = null;*/
    //vssql = Base64.encode(Base64.decode(vssql).replace("/*sqlwhere*/", pswhere));
    // return DealAjax.execSelectSql(dbsrc, vssql).Rows;
    if (pscxid == "default" || pscxid == "defalut") return [];
    return DealAjax.getDatatableBySqlid(pscxid, pswhere, '', '', '', '', noauth).Rows;
};


function getRowFromDt(dt, fieldstr, valstr) {
    var row = null;
    if (dt && dt.Rows && dt.Rows.length && dt.Rows.length > 0) {
        for (var i = 0; i < dt.Rows.length; i++) {
            if (dt.Rows[i][fieldstr] == valstr) {
                row = dt.Rows[i];
                break;
            }
        }
    }
    return row;
}
/*------------金额大写--------------------------------------------------------------------------------------------*/
function JEUpper(numberValue) {
    numberValue = (numberValue + "").replace(/,/g, "");
    var vsJEVal = numberValue;
    if (numberValue.indexOf("-") == 0) numberValue = numberValue.substr(1);
    numberValue = new String(Math.round(numberValue * 100)); // 数字金额
    var chineseValue = ""; // 转换后的汉字金额
    var String1 = "零壹贰叁肆伍陆柒捌玖"; // 汉字数字
    var String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"; // 对应单位
    var len = numberValue.length; // numberValue 的字符串长度
    var Ch1; // 数字的汉语读法
    var Ch2; // 数字位的汉字读法
    var nZero = 0; // 用来计算连续的零值的个数
    var String3; // 指定位置的数值
    if (len > 15) {
        alert("超出计算范围");
        return "";
    }
    if (numberValue == 0) {
        chineseValue = "零元整";
        return chineseValue;
    }
    String2 = String2.substr(String2.length - len, len);
    // 取出对应位数的STRING2的值
    for (var i = 0; i < len; i++) {
        String3 = parseInt(numberValue.substr(i, 1), 10);
        // 取出需转换的某一位的值
        if (i != (len - 3) && i != (len - 7) && i != (len - 11) && i != (len - 15)) {
            if (String3 == 0) {
                Ch1 = "";
                Ch2 = "";
                nZero = nZero + 1;
            } else if (String3 != 0 && nZero != 0) {
                Ch1 = "零" + String1.substr(String3, 1);
                Ch2 = String2.substr(i, 1);
                nZero = 0;
            } else {
                Ch1 = String1.substr(String3, 1);
                Ch2 = String2.substr(i, 1);
                nZero = 0;
            }
        } else {
            // 该位是万亿，亿，万，元位等关键位
            if (String3 != 0 && nZero != 0) {
                Ch1 = "零" + String1.substr(String3, 1);
                Ch2 = String2.substr(i, 1);
                nZero = 0;
            } else if (String3 != 0 && nZero == 0) {
                Ch1 = String1.substr(String3, 1);
                Ch2 = String2.substr(i, 1);
                nZero = 0;
            } else if (String3 == 0 && nZero >= 3) {
                Ch1 = "";
                Ch2 = "";
                nZero = nZero + 1;
            } else {
                Ch1 = "";
                Ch2 = String2.substr(i, 1);
                nZero = nZero + 1;
            }
            if (i == (len - 11) || i == (len - 3)) {
                // 如果该位是亿位或元位，则必须写上
                Ch2 = String2.substr(i, 1);
            }
        }
        chineseValue = chineseValue + Ch1 + Ch2;
    }
    if (String3 == 0) { // 最后一位（分）为0时，加上“整”
        chineseValue = chineseValue + "整";
    }
    if (vsJEVal.indexOf("-") == 0) chineseValue = "负" + chineseValue;
    return chineseValue;
}
/*---end---------金额大写--------------------------------------------------------------------------------------------*/
/*------------数字千分位相关--------------------------------------------------------------------------------------------*/
function commafy(n) { //千分位格式化
    n = decommafy(n);
    var narr = n.split('.');
    n = narr[0];
    var isFS = false;
    if (n.indexOf('-') == 0) {
        isFS = true;
        n = n.substr(1);
    }
    //必须是以d{3}结尾，前面必须是1-3个数字，但替换的时候，不包含结尾的d{3}个数字。 
    var re = /\d{1,3}(?=(\d{3})+$)/g;
    var n1 = n.replace(/^(\d+)((\.\d*)?)$/, function(s, s1, s2) { return s1.replace(re, "$&,") + s2; });
    return (isFS ? "-" : "") + n1 + (narr.length == 2 ? "." + narr[1] : "");
}

function decommafy(n) { //去千分位
    n = String(n);
    if ((n + "").trim() == "") {
        return "";
    }

    n = n + "";
    n = n.replace(/,/gi, '');
    return n;
}

/*------end------数字千分位相关--------------------------------------------------------------------------------------------*/

/*-----------替换条件--------------------------------------------*/

function analysisHelpWhere(wherestr, props, srcCtrlID) {
    wherestr = Base64.decode(wherestr);
    wherestr = dealCtrlField(wherestr, props);
    wherestr = dealDefEditField(wherestr, props);
    wherestr = dealCtrlSession(wherestr, props);
    wherestr = dealCtrlJs(wherestr, props);
    wherestr = dealUsualParam(wherestr);
    return wherestr;
}

function dealUsualParam(wherestr) {
    if (!$.url.param('UsualPara')) return wherestr;
    var pval = $.url.param('UsualPara');
    var keyarr = pval.split('`');
    for (var i = 0; i < keyarr.length; i++) {
        var valarr = keyarr[i].split('=');
        while (wherestr.indexOf("{" + valarr[0] + "}") != -1) {
            wherestr = wherestr.replace("{" + valarr[0] + "}", valarr[1]);
        }
    }
    return wherestr;
}

function dealCtrlField(wherestr, props) {
    var rearr = wherestr.match(new RegExp(/\#\w+\#/g));
    if (rearr && rearr.length > 0) {
        for (var i = 0; i < rearr.length; i++) {
            var fieldid = rearr[i].replace(/\#/g, "");
            if (props.gridEditParm && props.gridEditParm.record && props.gridEditParm.record[fieldid]) {
                wherestr = wherestr.replace(rearr[i], props.gridEditParm.record[fieldid]);
            } else if ($("#" + fieldid).length > 0) {
                wherestr = wherestr.replace(rearr[i], $("#" + fieldid).val());
            } else {
                wherestr = wherestr.replace(rearr[i], "");
            }
        }
    }
    return wherestr;
}

function dealDefEditField(wherestr, props) {
    var rearr = wherestr.match(new RegExp(/\@\w+\@/g));
    if (rearr && rearr.length > 0) {
        for (var i = 0; i < rearr.length; i++) {
            var fieldid = rearr[i].replace(/\@/g, "");
            if (props.gridEditParm && props.gridEditParm.record && props.gridEditParm.record[fieldid]) {
                wherestr = wherestr.replace(rearr[i], props.gridEditParm.record[fieldid]);
            } else if (typeof MainCardObj != "undefined" && MainCardObj != null && MainCardObj[fieldid]) {
                wherestr = wherestr.replace(rearr[i], MainCardObj[fieldid]);
            } else {
                wherestr = wherestr.replace(rearr[i], "");
            }
        }
    }
    return wherestr;
}

function dealCtrlSession(wherestr, props) {
    var rearr = wherestr.match(new RegExp(/\$\w+\$/g));
    if (rearr && rearr.length > 0) {
        for (var i = 0; i < rearr.length; i++) {
            var fieldid = rearr[i].replace(/\$/g, "");
            if (GSIDPSession["GENERSOFT.BS.PUBLIC." + fieldid]) {
                wherestr = wherestr.replace(rearr[i], GSIDPSession["GENERSOFT.BS.PUBLIC." + fieldid]);
            }
        }
    }
    return wherestr;
}

function dealCtrlJs(wherestr, props) {
    var rearr = wherestr.match(new RegExp(/\~[\W|\w]*\~/g));
    if (rearr && rearr.length > 0) {
        for (var i = 0; i < rearr.length; i++) {
            var jsstr = rearr[i];
            var reval = eval(jsstr.replace(/\~/g, ""));
            wherestr = wherestr.replace(rearr[i], reval);
        }
    }
    return wherestr;
}

function getUsualParam(paramName) {
    if (!$.url.param('UsualPara')) return "";
    var pval = $.url.param('UsualPara');
    var keyarr = pval.split('`');
    for (var i = 0; i < keyarr.length; i++) {
        var valarr = keyarr[i].split('=');
        if (valarr[0] == paramName) return valarr[1];
    }
    return "";
}


/*----------end 替换条件-------------------------------------------------------------------------*/
/*----框架使用---------------------------------------------------------------------------------------------------------------------*/
function openurl(id, name, url, isrtf, reload) {
    try {
        if (url.indexOf('/') != 0 && url.toLowerCase().indexOf('http://') != 0)
            url = "/cwbase/web/session/GSIDP/GSYS/WEB/" + url;
        if (!isrtf) {
            id = id + (new Date()).getTime();
        }
        var isInWinfrom = ('external' in window) && ('GetSession' in window.external);
        if (isInWinfrom) {
            window.external.OpenFuncForWeb(id, name, url, reload || false);
            return;
        }
        if (window.top.gsp && window.top.gsp.rtf.allFunc) {
            var ops = { "id": id, "name": name, "url": url };
            window.parent.top.gsp.rtf.allFunc.openUrl(ops); //.rtf.func.openUrl(ops); 
            return;
        }
        window.open(url);
    } catch (e) {
        window.open(url);
    }
}

function closeurl() {
    var bl = false;
    try {
        if (window.top.gsp && window.top.gsp.rtf.allFunc) {
            window.top.gsp.rtf.allFunc.close($.url.param('funcid'));
            bl = true;
        }
    } catch (e) {}
    if (!bl) {
        var pwin = window.parent;
        while (pwin != pwin.parent) {
            pwin = pwin.parent;
        }
        if (window.opener == undefined) {
            window.opener = null;
            window.open("", "_self");
        }
        if (pwin == window) {
            window.close();
        } else {
            pwin.close();
        }
    }
}

function RefreshParentWinGrid() {
    try {
        window.ISRefreshParentWinGrid = window.ISRefreshParentWinGrid || false;
        if ($.url.param("opertype") != "view" && window.opener &&
            window.opener.simpleGrid && window.opener.simpleGrid.grid) {
            //window.opener.simpleGrid.grid.loadData(); //刷新grid
            window.opener.simpleGrid.search(); //刷新grid
            window.ISRefreshParentWinGrid = true;
        } else {
            window.opener = null;
            window.open("", "_self");
        }
    } catch (ex) {
        return;
    }
}
if ("undefined" == typeof gsp) {
    gsp = {};
    gsp.rtf = {};
    gsp.rtf.childIframe = {};
    gsp.rtf.childIframe.close = function() {

        var funcid = $.url.param('funcid');
        funcid = funcid.substr(0, funcid.length - 13); //13 为时间字符的长度
        var frmid = "rtf_frm_" + $.url.param('funcid');
        //当前窗体
        var curwin = window.top.document.getElementById(frmid).contentWindow;
        if (curwin && $.url.param('opertype', curwin.location.href)) {
            var pfrmid = "rtf_frm_" + funcid.substr(0, funcid.length - $.url.param('opertype', curwin.location.href).length);
            //列表窗体
            if (window.top.document.getElementById(pfrmid) && window.top.document.getElementById(pfrmid).contentWindow && window.top.document.getElementById(pfrmid).contentWindow.simpleGrid)
                window.top.document.getElementById(pfrmid).contentWindow.simpleGrid.search();
        }
        return true;
    };
}
//$.data($('#mainTab')[0], 'tabs').options.onBeforeClose = function () { alert(1) }
/*----end -------------------框架使用-----------------------------------*/



jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
//JS DES加密函数
var _a_key_single_info = "20150623";

function jse(message) {
    var ciphertext = stringToHex(des_info_data(_a_key_single_info, message, 1, 0));
    return ciphertext;
}

//JS DES解密函数
function jsd(message) {
    var plaintext = des_info_data(_a_key_single_info, HexTostring(message), 0, 0);
    return plaintext;
}

//加解密主函数
function des_info_data(key, message, encrypt, mode, iv) {
    if (!message) {
        return "";
    }
    var spfunction1 = new Array(0x1010400, 0, 0x10000, 0x1010404, 0x1010004, 0x10404, 0x4, 0x10000, 0x400, 0x1010400, 0x1010404, 0x400, 0x1000404, 0x1010004, 0x1000000, 0x4, 0x404, 0x1000400, 0x1000400, 0x10400, 0x10400, 0x1010000, 0x1010000, 0x1000404, 0x10004, 0x1000004, 0x1000004, 0x10004, 0, 0x404, 0x10404, 0x1000000, 0x10000, 0x1010404, 0x4, 0x1010000, 0x1010400, 0x1000000, 0x1000000, 0x400, 0x1010004, 0x10000, 0x10400, 0x1000004, 0x400, 0x4, 0x1000404, 0x10404, 0x1010404, 0x10004, 0x1010000, 0x1000404, 0x1000004, 0x404, 0x10404, 0x1010400, 0x404, 0x1000400, 0x1000400, 0, 0x10004, 0x10400, 0, 0x1010004);
    var spfunction2 = new Array(-0x7fef7fe0, -0x7fff8000, 0x8000, 0x108020, 0x100000, 0x20, -0x7fefffe0, -0x7fff7fe0, -0x7fffffe0, -0x7fef7fe0, -0x7fef8000, -0x8000000, -0x7fff8000, 0x100000, 0x20, -0x7fefffe0, 0x108000, 0x100020, -0x7fff7fe0, 0, -0x8000000, 0x8000, 0x108020, -0x7ff00000, 0x100020, -0x7fffffe0, 0, 0x108000, 0x8020, -0x7fef8000, -0x7ff00000, 0x8020, 0, 0x108020, -0x7fefffe0, 0x100000, -0x7fff7fe0, -0x7ff00000, -0x7fef8000, 0x8000, -0x7ff00000, -0x7fff8000, 0x20, -0x7fef7fe0, 0x108020, 0x20, 0x8000, -0x8000000, 0x8020, -0x7fef8000, 0x100000, -0x7fffffe0, 0x100020, -0x7fff7fe0, -0x7fffffe0, 0x100020, 0x108000, 0, -0x7fff8000, 0x8020, -0x8000000, -0x7fefffe0, -0x7fef7fe0, 0x108000);
    var spfunction3 = new Array(0x208, 0x8020200, 0, 0x8020008, 0x8000200, 0, 0x20208, 0x8000200, 0x20008, 0x8000008, 0x8000008, 0x20000, 0x8020208, 0x20008, 0x8020000, 0x208, 0x8000000, 0x8, 0x8020200, 0x200, 0x20200, 0x8020000, 0x8020008, 0x20208, 0x8000208, 0x20200, 0x20000, 0x8000208, 0x8, 0x8020208, 0x200, 0x8000000, 0x8020200, 0x8000000, 0x20008, 0x208, 0x20000, 0x8020200, 0x8000200, 0, 0x200, 0x20008, 0x8020208, 0x8000200, 0x8000008, 0x200, 0, 0x8020008, 0x8000208, 0x20000, 0x8000000, 0x8020208, 0x8, 0x20208, 0x20200, 0x8000008, 0x8020000, 0x8000208, 0x208, 0x8020000, 0x20208, 0x8, 0x8020008, 0x20200);
    var spfunction4 = new Array(0x802001, 0x2081, 0x2081, 0x80, 0x802080, 0x800081, 0x800001, 0x2001, 0, 0x802000, 0x802000, 0x802081, 0x81, 0, 0x800080, 0x800001, 0x1, 0x2000, 0x800000, 0x802001, 0x80, 0x800000, 0x2001, 0x2080, 0x800081, 0x1, 0x2080, 0x800080, 0x2000, 0x802080, 0x802081, 0x81, 0x800080, 0x800001, 0x802000, 0x802081, 0x81, 0, 0, 0x802000, 0x2080, 0x800080, 0x800081, 0x1, 0x802001, 0x2081, 0x2081, 0x80, 0x802081, 0x81, 0x1, 0x2000, 0x800001, 0x2001, 0x802080, 0x800081, 0x2001, 0x2080, 0x800000, 0x802001, 0x80, 0x800000, 0x2000, 0x802080);
    var spfunction5 = new Array(0x100, 0x2080100, 0x2080000, 0x42000100, 0x80000, 0x100, 0x40000000, 0x2080000, 0x40080100, 0x80000, 0x2000100, 0x40080100, 0x42000100, 0x42080000, 0x80100, 0x40000000, 0x2000000, 0x40080000, 0x40080000, 0, 0x40000100, 0x42080100, 0x42080100, 0x2000100, 0x42080000, 0x40000100, 0, 0x42000000, 0x2080100, 0x2000000, 0x42000000, 0x80100, 0x80000, 0x42000100, 0x100, 0x2000000, 0x40000000, 0x2080000, 0x42000100, 0x40080100, 0x2000100, 0x40000000, 0x42080000, 0x2080100, 0x40080100, 0x100, 0x2000000, 0x42080000, 0x42080100, 0x80100, 0x42000000, 0x42080100, 0x2080000, 0, 0x40080000, 0x42000000, 0x80100, 0x2000100, 0x40000100, 0x80000, 0, 0x40080000, 0x2080100, 0x40000100);
    var spfunction6 = new Array(0x20000010, 0x20400000, 0x4000, 0x20404010, 0x20400000, 0x10, 0x20404010, 0x400000, 0x20004000, 0x404010, 0x400000, 0x20000010, 0x400010, 0x20004000, 0x20000000, 0x4010, 0, 0x400010, 0x20004010, 0x4000, 0x404000, 0x20004010, 0x10, 0x20400010, 0x20400010, 0, 0x404010, 0x20404000, 0x4010, 0x404000, 0x20404000, 0x20000000, 0x20004000, 0x10, 0x20400010, 0x404000, 0x20404010, 0x400000, 0x4010, 0x20000010, 0x400000, 0x20004000, 0x20000000, 0x4010, 0x20000010, 0x20404010, 0x404000, 0x20400000, 0x404010, 0x20404000, 0, 0x20400010, 0x10, 0x4000, 0x20400000, 0x404010, 0x4000, 0x400010, 0x20004010, 0, 0x20404000, 0x20000000, 0x400010, 0x20004010);
    var spfunction7 = new Array(0x200000, 0x4200002, 0x4000802, 0, 0x800, 0x4000802, 0x200802, 0x4200800, 0x4200802, 0x200000, 0, 0x4000002, 0x2, 0x4000000, 0x4200002, 0x802, 0x4000800, 0x200802, 0x200002, 0x4000800, 0x4000002, 0x4200000, 0x4200800, 0x200002, 0x4200000, 0x800, 0x802, 0x4200802, 0x200800, 0x2, 0x4000000, 0x200800, 0x4000000, 0x200800, 0x200000, 0x4000802, 0x4000802, 0x4200002, 0x4200002, 0x2, 0x200002, 0x4000000, 0x4000800, 0x200000, 0x4200800, 0x802, 0x200802, 0x4200800, 0x802, 0x4000002, 0x4200802, 0x4200000, 0x200800, 0, 0x2, 0x4200802, 0, 0x200802, 0x4200000, 0x800, 0x4000002, 0x4000800, 0x800, 0x200002);
    var spfunction8 = new Array(0x10001040, 0x1000, 0x40000, 0x10041040, 0x10000000, 0x10001040, 0x40, 0x10000000, 0x40040, 0x10040000, 0x10041040, 0x41000, 0x10041000, 0x41040, 0x1000, 0x40, 0x10040000, 0x10000040, 0x10001000, 0x1040, 0x41000, 0x40040, 0x10040040, 0x10041000, 0x1040, 0, 0, 0x10040040, 0x10000040, 0x10001000, 0x41040, 0x40000, 0x41040, 0x40000, 0x10041000, 0x1000, 0x40, 0x10040040, 0x1000, 0x41040, 0x10001000, 0x40, 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x40000, 0x10001040, 0, 0x10041040, 0x40040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, 0, 0x10041040, 0x41000, 0x41000, 0x1040, 0x1040, 0x40040, 0x10000000, 0x10041000);
    var keys = des_createKeys(key);
    var m = 0,
        i, j, temp, temp2, right1, right2, left, right, looping;
    var cbcleft, cbcleft2, cbcright, cbcright2;
    var endloop, loopinc;
    var len = message.length;
    var chunk = 0;
    var iterations = keys.length == 32 ? 3 : 9;

    if (iterations == 3) {
        looping = encrypt ? new Array(0, 32, 2) : new Array(30, -2, -2);
    } else {
        looping = encrypt ? new Array(0, 32, 2, 62, 30, -2, 64, 96, 2) : new Array(94, 62, -2, 32, 64, 2, 30, -2, -2);
    }

    message += "\0\0\0\0\0\0\0\0";
    result = "";
    tempresult = "";
    if (mode == 1) {
        cbcleft = (iv.charCodeAt(m++) << 24) | (iv.charCodeAt(m++) << 16) | (iv.charCodeAt(m++) << 8) | iv.charCodeAt(m++);
        cbcright = (iv.charCodeAt(m++) << 24) | (iv.charCodeAt(m++) << 16) | (iv.charCodeAt(m++) << 8) | iv.charCodeAt(m++);
        m = 0;
    }
    while (m < len) {
        if (encrypt) {
            left = (message.charCodeAt(m++) << 16) | message.charCodeAt(m++);
            right = (message.charCodeAt(m++) << 16) | message.charCodeAt(m++);
        } else {
            left = (message.charCodeAt(m++) << 24) | (message.charCodeAt(m++) << 16) | (message.charCodeAt(m++) << 8) | message.charCodeAt(m++);
            right = (message.charCodeAt(m++) << 24) | (message.charCodeAt(m++) << 16) | (message.charCodeAt(m++) << 8) | message.charCodeAt(m++);
        }

        if (mode == 1) {
            if (encrypt) {
                left ^= cbcleft;
                right ^= cbcright;
            } else {
                cbcleft2 = cbcleft;
                cbcright2 = cbcright;
                cbcleft = left;
                cbcright = right;
            }
        }

        temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
        right ^= temp;
        left ^= (temp << 4);
        temp = ((left >>> 16) ^ right) & 0x0000ffff;
        right ^= temp;
        left ^= (temp << 16);
        temp = ((right >>> 2) ^ left) & 0x33333333;
        left ^= temp;
        right ^= (temp << 2);
        temp = ((right >>> 8) ^ left) & 0x00ff00ff;
        left ^= temp;
        right ^= (temp << 8);
        temp = ((left >>> 1) ^ right) & 0x55555555;
        right ^= temp;
        left ^= (temp << 1);
        left = ((left << 1) | (left >>> 31));
        right = ((right << 1) | (right >>> 31));
        for (j = 0; j < iterations; j += 3) {
            endloop = looping[j + 1];
            loopinc = looping[j + 2];
            for (i = looping[j]; i != endloop; i += loopinc) {
                right1 = right ^ keys[i];
                right2 = ((right >>> 4) | (right << 28)) ^ keys[i + 1];
                temp = left;
                left = right;
                right = temp ^ (spfunction2[(right1 >>> 24) & 0x3f] | spfunction4[(right1 >>> 16) & 0x3f] | spfunction6[(right1 >>> 8) & 0x3f] | spfunction8[right1 & 0x3f] | spfunction1[(right2 >>> 24) & 0x3f] | spfunction3[(right2 >>> 16) & 0x3f] | spfunction5[(right2 >>> 8) & 0x3f] | spfunction7[right2 & 0x3f]);
            }

            temp = left;
            left = right;
            right = temp;
        }
        left = ((left >>> 1) | (left << 31));
        right = ((right >>> 1) | (right << 31));
        temp = ((left >>> 1) ^ right) & 0x55555555;
        right ^= temp;
        left ^= (temp << 1);
        temp = ((right >>> 8) ^ left) & 0x00ff00ff;
        left ^= temp;
        right ^= (temp << 8);
        temp = ((right >>> 2) ^ left) & 0x33333333;
        left ^= temp;
        right ^= (temp << 2);
        temp = ((left >>> 16) ^ right) & 0x0000ffff;
        right ^= temp;
        left ^= (temp << 16);
        temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
        right ^= temp;
        left ^= (temp << 4);
        if (mode == 1) {
            if (encrypt) {
                cbcleft = left;
                cbcright = right;
            } else {
                left ^= cbcleft2;
                right ^= cbcright2;
            }
        }

        if (encrypt) {
            tempresult += String.fromCharCode((left >>> 24), ((left >>> 16) & 0xff), ((left >>> 8) & 0xff), (left & 0xff), (right >>> 24), ((right >>> 16) & 0xff), ((right >>> 8) & 0xff), (right & 0xff));
        } else {
            tempresult += String.fromCharCode(((left >>> 16) & 0xffff), (left & 0xffff), ((right >>> 16) & 0xffff), (right & 0xffff));
        }

        encrypt ? chunk += 16 : chunk += 8;

        if (chunk == 512) {
            result += tempresult;
            tempresult = "";
            chunk = 0;
        }
    }

    return result + tempresult;
}

//密钥生成函数
function des_createKeys(key) {
    pc2bytes0 = new Array(0, 0x4, 0x20000000, 0x20000004, 0x10000, 0x10004, 0x20010000, 0x20010004, 0x200, 0x204, 0x20000200, 0x20000204, 0x10200, 0x10204, 0x20010200, 0x20010204);
    pc2bytes1 = new Array(0, 0x1, 0x100000, 0x100001, 0x4000000, 0x4000001, 0x4100000, 0x4100001, 0x100, 0x101, 0x100100, 0x100101, 0x4000100, 0x4000101, 0x4100100, 0x4100101);
    pc2bytes2 = new Array(0, 0x8, 0x800, 0x808, 0x1000000, 0x1000008, 0x1000800, 0x1000808, 0, 0x8, 0x800, 0x808, 0x1000000, 0x1000008, 0x1000800, 0x1000808);
    pc2bytes3 = new Array(0, 0x200000, 0x8000000, 0x8200000, 0x2000, 0x202000, 0x8002000, 0x8202000, 0x20000, 0x220000, 0x8020000, 0x8220000, 0x22000, 0x222000, 0x8022000, 0x8222000);
    pc2bytes4 = new Array(0, 0x40000, 0x10, 0x40010, 0, 0x40000, 0x10, 0x40010, 0x1000, 0x41000, 0x1010, 0x41010, 0x1000, 0x41000, 0x1010, 0x41010);
    pc2bytes5 = new Array(0, 0x400, 0x20, 0x420, 0, 0x400, 0x20, 0x420, 0x2000000, 0x2000400, 0x2000020, 0x2000420, 0x2000000, 0x2000400, 0x2000020, 0x2000420);
    pc2bytes6 = new Array(0, 0x10000000, 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002, 0, 0x10000000, 0x80000, 0x10080000, 0x2, 0x10000002, 0x80002, 0x10080002);
    pc2bytes7 = new Array(0, 0x10000, 0x800, 0x10800, 0x20000000, 0x20010000, 0x20000800, 0x20010800, 0x20000, 0x30000, 0x20800, 0x30800, 0x20020000, 0x20030000, 0x20020800, 0x20030800);
    pc2bytes8 = new Array(0, 0x40000, 0, 0x40000, 0x2, 0x40002, 0x2, 0x40002, 0x2000000, 0x2040000, 0x2000000, 0x2040000, 0x2000002, 0x2040002, 0x2000002, 0x2040002);
    pc2bytes9 = new Array(0, 0x10000000, 0x8, 0x10000008, 0, 0x10000000, 0x8, 0x10000008, 0x400, 0x10000400, 0x408, 0x10000408, 0x400, 0x10000400, 0x408, 0x10000408);
    pc2bytes10 = new Array(0, 0x20, 0, 0x20, 0x100000, 0x100020, 0x100000, 0x100020, 0x2000, 0x2020, 0x2000, 0x2020, 0x102000, 0x102020, 0x102000, 0x102020);
    pc2bytes11 = new Array(0, 0x1000000, 0x200, 0x1000200, 0x200000, 0x1200000, 0x200200, 0x1200200, 0x4000000, 0x5000000, 0x4000200, 0x5000200, 0x4200000, 0x5200000, 0x4200200, 0x5200200);
    pc2bytes12 = new Array(0, 0x1000, 0x8000000, 0x8001000, 0x80000, 0x81000, 0x8080000, 0x8081000, 0x10, 0x1010, 0x8000010, 0x8001010, 0x80010, 0x81010, 0x8080010, 0x8081010);
    pc2bytes13 = new Array(0, 0x4, 0x100, 0x104, 0, 0x4, 0x100, 0x104, 0x1, 0x5, 0x101, 0x105, 0x1, 0x5, 0x101, 0x105);
    var iterations = key.length >= 24 ? 3 : 1;
    var keys = new Array(32 * iterations);
    var shifts = new Array(0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0);
    var lefttemp, righttemp, m = 0,
        n = 0,
        temp;

    for (var j = 0; j < iterations; j++) {
        left = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++);
        right = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++);
        temp = ((left >>> 4) ^ right) & 0x0f0f0f0f;
        right ^= temp;
        left ^= (temp << 4);
        temp = ((right >>> -16) ^ left) & 0x0000ffff;
        left ^= temp;
        right ^= (temp << -16);
        temp = ((left >>> 2) ^ right) & 0x33333333;
        right ^= temp;
        left ^= (temp << 2);
        temp = ((right >>> -16) ^ left) & 0x0000ffff;
        left ^= temp;
        right ^= (temp << -16);
        temp = ((left >>> 1) ^ right) & 0x55555555;
        right ^= temp;
        left ^= (temp << 1);
        temp = ((right >>> 8) ^ left) & 0x00ff00ff;
        left ^= temp;
        right ^= (temp << 8);
        temp = ((left >>> 1) ^ right) & 0x55555555;
        right ^= temp;
        left ^= (temp << 1);
        temp = (left << 8) | ((right >>> 20) & 0x000000f0);
        left = (right << 24) | ((right << 8) & 0xff0000) | ((right >>> 8) & 0xff00) | ((right >>> 24) & 0xf0);
        right = temp;

        for (i = 0; i < shifts.length; i++) {
            if (shifts[i]) {
                left = (left << 2) | (left >>> 26);
                right = (right << 2) | (right >>> 26);
            } else {
                left = (left << 1) | (left >>> 27);
                right = (right << 1) | (right >>> 27);
            }
            left &= -0xf;
            right &= -0xf;
            lefttemp = pc2bytes0[left >>> 28] | pc2bytes1[(left >>> 24) & 0xf] | pc2bytes2[(left >>> 20) & 0xf] | pc2bytes3[(left >>> 16) & 0xf] | pc2bytes4[(left >>> 12) & 0xf] | pc2bytes5[(left >>> 8) & 0xf] | pc2bytes6[(left >>> 4) & 0xf];
            righttemp = pc2bytes7[right >>> 28] | pc2bytes8[(right >>> 24) & 0xf] | pc2bytes9[(right >>> 20) & 0xf] | pc2bytes10[(right >>> 16) & 0xf] | pc2bytes11[(right >>> 12) & 0xf] | pc2bytes12[(right >>> 8) & 0xf] | pc2bytes13[(right >>> 4) & 0xf];
            temp = ((righttemp >>> 16) ^ lefttemp) & 0x0000ffff;
            keys[n++] = lefttemp ^ temp;
            keys[n++] = righttemp ^ (temp << 16);
        }
    }



    return keys;
}

//将普通的字符串转换成16进制代码的字符串
function stringToHex(s) {
    var r = "";
    var hexes = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
    for (var i = 0; i < (s.length); i++) { r += hexes[s.charCodeAt(i) >> 4] + hexes[s.charCodeAt(i) & 0xf]; }
    return r;
}

//将16进制代码的字符串转换成普通的字符串
function HexTostring(s) {
    var r = "";
    for (var i = 0; i < s.length; i += 2) { var sxx = parseInt(s.substring(i, i + 2), 16);
        r += String.fromCharCode(sxx); }
    return r;
}


function calcPixelsPerMM() {
    var px = 96 / 25.4;
    return px;
};
window.PxPerMM = window.PxPerMM || calcPixelsPerMM();
window.A4Width = 190;
window.A4Height = 270;


var langobj = {
    lang: "en",
    getLan: function() {
        var obj = "ch";
        if ($.cookie('GSPWebLanguageKey') !== "zh-CN") {
            obj = "en";
        } else {
            obj = "ch";
        }
        if ($.cookie('GSPWebLanguageKey') == null) {
            obj = "ch";
        }
        return obj;
    },
    get: function(key) {
        return langPackage[langobj.getLan()][key];
    }
};

var langPackage = {
    en: {
        "Tips": "Tips",
        "Warn": "Warn",
        "Ok": "Ok",
        "Cancel": "Cancel",
        "View": "View",
        "Edit": "Edit",
        "PleaseChoose": "PleaseChoose",
        "PleaseEdit": "PleaseEdit",
        "SelectOneRow": "please choose one record to submit！",
        "SelectRow": "please choose the record to be processed！",
        "AddSame": "new added same level",
        "Add": "Add",
        "AddDown": "new added subordinate",
        "Print": "Print",
        "WFNoEdit": "(submitted for approval / approval)   not allowed to modify!！",
        "ConfirmDelete": " do you confirm to delete this record？",
        "CanNotDeleteParentNode": "can not delete non-detail nodes!",
        "WFNoDelete": "The selected data (submitted for approval / approval) must not be deleted!",
        "WFNoDeleteNoPass": "The selected data (not approval) must not be deleted!！",
        "NOSelectWF": "process not chosen!",
        "SelectUser": "please chooose approver",
        "SelectWF": " please select the approval flow",
        "NoSelectUser": " please select the approval person!",
        "NoSelectWF": "process not chosen",
        "NOWorkFlow": "no association defined to process!",
        "NOWorkFlow1": "no approcal process defined to the business!",
        "NOWorkFlow2": " can not get relevant process, please define the process and link it to the collection!",
        "NOWorkFlow3": "no approcal process defined to the business!",
        "NOWorkFlowGraph": " can not view the process information until entering the approval flow!",
        "ViewWfLog": "view the audit log",
        "WFActivity": "activity name",
        "WFActivityUser": "leading official",
        "WFTime": "Time",
        "WFLog": "approval comments",
        "WFException": "approval flow abnormal!",
        "SubmitReject": "processed,can not be submitted repeatedly！",
        "SubmitSucess": "submitted successfully!",
        "CancelWFSucess": "cancel approval process successfully!",
        "CancelWFFailed": "process entered and can not be canceled!",
        "TimeBeginEndInValid": "the start date must not be later than the due date!",
        "MoneyStartEndInValid": " the starting amount can not be greater than the closing amount!",
        "PleaseChoose": "please choose",
        "PleaseWrite": "please input",
        "ViewFile": "check attachments",
        "FileName": "file name",
        "FileNameOp": "Operation",
        "FileDownLoad": "DownLoad",
        "FileView": "View",
        "Exit": "Exit",
        "QueryCondition": "query condition",
        "StandardQuery": "standard query",
        "MoreQuery": "advanced query",
        "DataList": "data list",
        "MyFavor": "my collection",
        "NoSelectRecord": "no record chosen!",
        "OpSucess": "operation success!",
        "ISExport": "Whether to export",
        "ExpTitle": "show name",
        "ExpOption": "Export options",
        "ConfirmExp": "Excel export",
        "ImportExcel": "Excel import",
        "DelTreeAttention": "note, delete the subordinates of tree nodes at the same time！",
        "TreeCopyOneAttention": "Tree list can only copy one line！",
        "Required": "data must be entered!",
        "YXSucess": "submit image failed!",
        "YXFailed": "submit images successfully!",
        "YXSave": "Please save the document, and then submit the image!",
        "YXSub": "Submit images!",
        "YXView": "View images!",
        "LeaveTips": "You have not been modified to save, whether to give up？",
        "SaveTemp": "staging",
        "NoPK": "NoPK！",
        "Upload": "Upload",
        "Close": "Close Window",
        "NotNull": "NotNull",
        "Insert": "Insert",
        "Delete": "Delete",
        "Copy": "Copy",
        "COLSAMEVAL": "clumn with the same value",
        "TreeHZ": "tree summary",
        "ExportExcel": "ExportExcel",
        "ZCSucess": "staging success！",
        "SaveSucess": "saved successfully！",
        "ConfirmDelete": "confirm deletion？",
        "CanotDeleteLeaf": "can not delete non-detail nodes!",
        "ConfirmDelete": "confirm deletion？",
        "error": "Error",
        "file": "FileUrl",
        "line": "LineNumber",
        "waittoupload": "waittoupload",
        "uploadedfile": "uploadedfile",
        "search": "search",
        "clear": "clear",
        "line": "line",
        "lineafter": "",
        "workcenter": "workcenter",
        "myfavor": "myfavor",
        "myfavor1": "myfavor",
        "risk": "risk info",
        "appstore": "appstore",
        "todo": "todo",
        "done": "done",
        "request": "request",
        "message": "message",
        "hello": "hello!",
        "appstore": "appstore",
        "NoPrintFomrat": "Not defined Print format",
        "ChoosePrint": "Choose Print Format",
        "PrintFormat": "File Type",
        "ChooseSelectFormat": "Please Choose Print Format",
        "wfzc": "暂存数据不能提交审批！",
        "noselectdata": "字典表未创建或没有值，对应字段{0}！",
        "nosavenowf": "单据未保存，不能提交审批！",
        "wfsbtn": "提交审批",
        "wfcbtn": "取消审批",
        "wfvbtn": "审批日志"
    },
    ch: {

        "Tips": "提示",
        "Warn": "警告",
        "Ok": "确定",
        "Cancel": "取消",
        "View": "浏览",
        "Edit": "维护",
        "PleaseChoose": "请选择",
        "PleaseEdit": "请输入",
        "SelectOneRow": "请选择一条记录进行处理！",
        "SelectRow": "请选中待处理的记录！",
        "AddSame": "新增同级",
        "Add": "新增",
        "AddDown": "新增下级",
        "Print": "打印",
        "WFNoEdit": "已（提交审批/审批通过）不允许修改！",
        "ConfirmDelete": "确实删除该条记录吗？",
        "CanNotDeleteParentNode": "不能删除非明细节点!",
        "WFNoDelete": "选中的数据已（提交审批/审批通过）不得删除！",
        "WFNoDeleteNoPass": "选中的数据已（审批不通过）不得删除！",
        "NOSelectWF": "没有选择流程!",
        "SelectUser": "请选择审批人",
        "SelectWF": "选择审批流程",
        "NoSelectUser": "请选择审批人!",
        "NoSelectWF": "没有选择流程!",
        "NOWorkFlow": "没有定义关联到流程!",
        "NOWorkFlow1": "该业务未定义审批流!",
        "NOWorkFlow2": "没有获取到相关流程，请定义流程并关联到类集!",
        "NOWorkFlow3": "该业务未定义审批流!",
        "NOWorkFlowGraph": "没有进入审批流，不能查看流程信息!",
        "ViewWfLog": "查看审批日志",
        "WFActivity": "活动名称",
        "WFActivityUser": "负责人",
        "WFTime": "时间",
        "WFLog": "审批意见",
        "WFException": "审批流异常!",
        "SubmitReject": "已处理,不能重复提交！",
        "SubmitSucess": "提交成功!",
        "CancelWFSucess": "取消审批流成功!",
        "CancelWFFailed": "已经进入流程无法取消!",
        "TimeBeginEndInValid": "开始日期不得晚于截止日期!",
        "MoneyStartEndInValid": "起始金额不得大于截止金额!",
        "PleaseChoose": "请选择",
        "PleaseWrite": "请输入",
        "ViewFile": "查看附件",
        "FileName": "文件名称",
        "FileNameOp": "操作",
        "FileDownLoad": "下载",
        "FileView": "查看",
        "Exit": "退出",
        "QueryCondition": "查询条件",
        "StandardQuery": "标准查询",
        "MoreQuery": "高级查询",
        "DataList": "数据列表",
        "MyFavor": "我的收藏",
        "NoSelectRecord": "没有选择记录!",
        "OpSucess": "操作成功!",
        "ISExport": "是否导出",
        "ExpTitle": "显示名称",
        "ExpOption": "导出选项",
        "ConfirmExp": "确定导出",
        "ImportExcel": "excel导入",
        "DelTreeAttention": "注意，同时删除树节点的下级！",
        "TreeCopyOneAttention": "树形列表只能复制一行！",
        "Required": "必须录入数据!",
        "YXSucess": "提交影像失败!",
        "YXFailed": "提交影像成功!",
        "YXSave": "请先保存单据，再提交影像!",
        "YXSub": "提交影像!",
        "YXView": "查看影像!",
        "LeaveTips": "您已修改还未保存，是否放弃？",
        "SaveTemp": "暂存",
        "NoPK": "未定义主键！",
        "Upload": "附件上传",
        "Close": "关闭",
        "NotNull": "不能为空",
        "Insert": "插入",
        "Delete": "删除",
        "Copy": "复制",
        "COLSAMEVAL": "列同值",
        "TreeHZ": "树级汇总",
        "ExportExcel": "导出Excel",
        "ZCSucess": "暂存成功！",
        "SaveSucess": "保存成功！",
        "ConfirmDelete": "确认删除吗？",
        "CanotDeleteLeaf": "不能删除非明细节点!",
        "ConfirmDelete": "确认删除吗？",
        "error": "错误信息",
        "file": "文件",
        "line": "行号",
        "waittoupload": "待上传文件",
        "uploadedfile": "已上传文件",
        "search": "查询",
        "clear": "清空",
        "line": "第",
        "lineater": "行",
        "line": "第",
        "lineafter": "行",
        "workcenter": "工作中心",
        "myfavor": "常用功能",
        "myfavor1": "分析查询",
        "risk": "预警监控",
        "appstore": "应用商城",
        "todo": "待我审批",
        "done": "我已审批",
        "request": "我的请求",
        "message": "消息",
        "hello": "您好!",
        "appstore": "应用商城",
        "NoPrintFomrat": "未定义打印格式",
        "ChoosePrint": "选择打印格式",
        "PrintFormat": "文件格式",
        "ChooseSelectFormat": "请选择打印格式！",
        "wfzc": "暂存数据不能提交审批！",
        "noselectdata": "字典表未创建或没有值，对应字段{0}！",
        "nosavenowf": "单据未保存，不能提交审批！",
        "wfsbtn": "提交审批",
        "wfcbtn": "取消审批",
        "wfvbtn": "审批日志"
            //langobj.get("NoPK")

    } //
};




/*浮点数计算方法*/
//加法
function add(a, b) {
    var c, d, e;
    try {
        c = a.toString().split(".")[1].length;
    } catch (f) {
        c = 0;
    }
    try {
        d = b.toString().split(".")[1].length;
    } catch (f) {
        d = 0;
    }
    return e = Math.pow(10, Math.max(c, d)), (mul(a, e) + mul(b, e)) / e;
}
//减法
function sub(a, b) {
    var c, d, e;
    try {
        c = a.toString().split(".")[1].length;
    } catch (f) {
        c = 0;
    }
    try {
        d = b.toString().split(".")[1].length;
    } catch (f) {
        d = 0;
    }
    return e = Math.pow(10, Math.max(c, d)), (mul(a, e) - mul(b, e)) / e;
}
//乘法
function mul(a, b) {
    var c = 0,
        d = a.toString(),
        e = b.toString();
    try {
        c += d.split(".")[1].length;
    } catch (f) {}
    try {
        c += e.split(".")[1].length;
    } catch (f) {}
    return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c);
}
//除法
function div(a, b) {
    var c, d, e = 0,
        f = 0;
    try {
        e = a.toString().split(".")[1].length;
    } catch (g) {}
    try {
        f = b.toString().split(".")[1].length;
    } catch (g) {}
    return c = Number(a.toString().replace(".", "")), d = Number(b.toString().replace(".", "")), mul(c / d, Math.pow(10, f - e));
}


function openLoading(title) {
    title = title || "正在加载中...";
    interval = title || 50;
    var dialog = $("<div style='padding:10px 10px 10px 10px'><div class='loader' style='text-align:center'>" +
        " <img src='css/images/loading-tip.gif'>" +
        "</div>" +
        "<div   style='text-align:center;margin-top:5px;' >" + title + "</div></div>");
    return $.ligerDialog.open({ target: dialog, allowClose: false, width: "200" });
}


//过滤中文
function replceChinese(str) {
    if (str == null || str == '') {
        return str;
    }
    if (GSIDPSession["LANGUAGE"].toString().toUpperCase() === 'EN-US') {
        var reg = new RegExp("[\u4e00-\u9fa5]", "g");
        var matches = str.match(reg);
        if (matches != null) {
            for (var i = 0; i < matches.length; i++) {
                str = str.replace(matches[i], '');
            }
        }
    }
    return str;
}

var security = {
    encode: function(message) {
        return jse(message);
    },
    decode: function(message) {
        return jsd(message);
    }
}

//export security.
exports.security = security;